如何将字符串
"I am is a 快乐的 boy yeah." 
反转为
"yeah boy 的乐快 a is am  I."

解决方案 »

  1.   

    String[] sts = s.split(" ");
    StringBuffer sb = new StringBuffer();
    for(int i = sts.length-1; i>=0;i--){
      sb.append(sts[i]);
    }
    return sb.toString();
      

  2.   

    String str = "I am is a 快乐的 boy yeah.";
    String[] c = str.split(" ");
    for (int i = c.length - 1; i >= 0; i--)
    System.out.print(c[i] + " "); 
    唉,那个快乐的没法弄啊。。还请高人。
      

  3.   

    public static void main(String[] args) {
    String s = "I am is a 快乐的 boy yeah.";
    String[] sts = s.split(" ");
    StringBuffer sb = new StringBuffer();
    for (int i = sts.length - 1; i >= 0; i--) {
    boolean is = false;
    for (int k = 0; k < sts[i].length(); k++) {
    if (sts[i].substring(k, k + 1).matches("[\u4e00-\u9fa5]+")) {
    System.out.println(sts[i].substring(k, k + 1));
    is = true;
    break;
    }
    }
    if (is) {
    System.out.println("go");
    for (int n = sts[i].length() - 1; n >=0; n--) {
     sb.append(sts[i].substring(n,n+1));
    }
    sb.append(" ");
     continue;
    }
    sb.append(sts[i]+" "); } System.out.println(sb.toString());
    }
    ===你试试上面的代码。
    不过,需要改进的进方是:英文的标点符号里的记号“.”。可以在上面改改
      

  4.   

    哦,忘了,结果是:
    yeah. boy 的乐快 a is am I ----很奇怪,那个标点符号不知怎么搞的,在第二个位置上。
      

  5.   

    哦,忘了,结果是:
    yeah. boy 的乐快 a is am I ----很奇怪,那个标点符号不知怎么搞的,在第二个位置上。
      

  6.   


    赚分来啦!!
            public static void main(String[] args) {
    String a =" 13264284745 杨凯 你好";
    char [] aChar = a.toCharArray();
    a="";
    for(int i=aChar.length-1;i>=0;i--){
    System.out.println(i-1);
    a+=aChar[i];
    }
    System.out.println(a);
    }
      

  7.   

    哦,忘了,结果是:
    yeah. boy 的乐快 a is am I ----很奇怪,那个标点符号不知怎么搞的,在第二个位置上。
      

  8.   

    英文单词的反转简单,空白符作分割,使用 java.util.Scanner 就成。中文字符的判断和反转也不难,但要根据语义对中文词汇进行划分再反转就比较麻烦了。
      

  9.   

    偷懒给你拼了下,呵呵,玩嘛import java.util.*;public class csdntest2 {
        public static void main(String[] args) {
         String str = "I am is a 快乐的 boy yeah";
         StringBuffer sb = new StringBuffer();
         StringBuffer sb1 = new StringBuffer();
         sb.append(str);
         String str1 = sb.reverse().toString();
         //System.out.println(sb.toString());
         String[] strs = str1.split(" ");
         for(int i = 0; i <strs.length; i ++){
         if(!strs[i].equals("的乐快")){
         sb1.append(strs[i]);
         String str2 = sb1.reverse().toString();
         strs[i] = str2;
         sb1.delete(0, strs[i].length());
         }
         System.out.print(strs[i] + " ");
         }
         System.out.print(".");
        }
        
    }  输出结果:yeah boy 的乐快 a is am I .
      

  10.   

    public class Test {
    /**
     * @param args
     */
    public static void main(String[] args) {
    String str = "I am is a 快乐的 boy yeah.";
    str = str.substring(0, str.indexOf("."));
    String[] strArr = str.split(" ");
    StringBuffer sb = new StringBuffer();
    for (int i = strArr.length - 1; i > -1; i--) {
    String s = strArr[i];
    //区分是汉字还是字母
    if(s.length() == s.getBytes().length) {
    sb.append(s);
    }
    else {
    //汉字时,再倒序
    for(int j = s.length(); j > 0; j--) {
    sb.append(s.substring(j - 1, j));
    }
    }
    if (i != 0) {
    sb.append(" ");
    }
    else {
    sb.append(".");
    }
    }
    System.out.println(sb.toString());
    }
    }
      

  11.   


    public class Test {
    /**
     * @param args
     */
    public static void main(String[] args) {
    String str = "I am is a 快乐的 boy yeah.";
    str = str.substring(0, str.indexOf("."));
    String[] strArr = str.split(" ");
    StringBuffer sb = new StringBuffer();
    for (int i = strArr.length - 1; i > -1; i--) {
    String s = strArr[i];
    //区分是汉字还是字母
    if(s.length() == s.getBytes().length) {
    sb.append(s);
    }
    else {
    //汉字时,再倒序
    for(int j = s.length(); j > 0; j--) {
    sb.append(s.substring(j - 1, j));
    }
    }
    if (i != 0) {
    sb.append(" ");
    }
    else {
    sb.append(".");
    }
    }
    System.out.println(sb.toString());
    }
    }
      

  12.   


    谢谢大家的提醒,已解决.
    首先感谢17楼的提醒,用Scanner已经解决.再次感谢.
    再次感谢辛勤回帖的勤劳的人民.你们的回复也提示了我.谢谢.
    马上结贴.