如何将输入的英文反过来输出。
例如输入: nice to meet you!  
输出就是: !you meet to nicepublic class ReverseOutput {
         public static void main(String[] args) {
String s = "hello world.how are you?i fine.and you?nice to meet you!me to!";
new Reverse().doRoput(s);
}
}class Reverse {
Reverse() {} public void doRoput(String str) {
          //在这里写实现代码
}}

解决方案 »

  1.   

    自己搜索一下,CSDN 有很多这样的帖子
      

  2.   

    System.out.println(new StringBuilder(str).reverse().toString());
      

  3.   

    这种题目请先行自己做,做不出来的时候,再来 CSDN 问你所碰到的问题。而不是一上来就让人写所有的代码!
      

  4.   

    StringBuffer自带了方法reverse,所以:StringBuffer strBuffer = new StringBuffer(str);
    strBuffer.reverse();
    System.out.println(strBuffer.toString());
      

  5.   

    dollyn 这个是全部反过来的。
    我需要的是 输入: hello world.
     输出: .world hello  
      

  6.   

    public class ReverseOutput {
             public static void main(String[] args) {
            String s = "hello world.how are you?i fine.and you?nice to meet you!me to!";
            new Reverse().doRoput(s);
        }
    }class Reverse {
        Reverse() {}    public void doRoput(String str) {
              //在这里写实现代码
         int i = str.length();
         while(i > 0){
         System.out.print(str.substring(i-1,i));
         i--;
         }
        }}
      

  7.   

    提供2种思路:
    第一种通过字符数组import java.util.*;public class Palindrome1
    {
      public static void main(String[] args)
      {
       Scanner sc = new Scanner(System.in);
      
       System.out.println("Enter a string: ");
       String word = sc.next();
       int i = word.length();
       int j = 0;
      
       while (j <= (i / 2) -1 && word.charAt(j) == word.charAt(i - j - 1))
         j++;
      
       if (j == i / 2) 
        System.out.println("The string is palindrome.");
       else 
        System.out.println("The string is not palindrome.");
       }
    }第二种通过StringBuffer的方法import java.util.*;public class Palindrome2
    {
      public static void main(String[] args)
      {
       Scanner sc = new Scanner(System.in);
      
       System.out.println("Enter a string: ");
       String word = sc.next();
       
       if (word.equals(new StringBuffer(word).reverse().toString()))
          System.out.println("The string is palindrome.");
       else
          System.out.println("The string is not palindrome.");
       }
    }
      

  8.   

    System.out.println(new StringBuilder(str).reverse().toString());
    就可以了,在java中游转移的方法直接调用就可以了
      

  9.   

    import java.util.*;
    import java.util.regex.*;
    //....
        public void doRoput(String str) {
         Stack<String> reverseString=new Stack<String>();
         String regex="[^\\w]";
        
         Matcher m=Pattern.compile(regex).matcher(str);
         int start=0,end=0;
         while(m.find()){
         if(start==m.start()){
         reverseString.push(m.group());
        
         }else{
         reverseString.push(str.substring(start,m.start()));
         reverseString.push(m.group());
         }
         start=m.end();
         }
         if(start!=str.length()-1){
         reverseString.push(str.substring(start));
         }
         while(!reverseString.empty()){
         System.out.print(reverseString.pop());
         }
         System.out.println();
        }
      

  10.   

    楼主 ,我的比较好理解:public class MyString {
    public static void main(String[] args) {
    String string="Hello Word     da jia hao !";
    String[] strs=string.split(" ");
    StringBuilder sb=new StringBuilder();
    for(int i=strs.length-1;i>0;i--){
    sb.append(strs[i]+" ");
    }
    sb.append(strs[0]);
    String newStr=sb.toString();
    System.out.println(newStr);
    }
                    /**
     * 如果把
     * for(int i=strs.length-1;i>0;i--){
     * sb.append(strs[i]+" ");
     * }
     * sb.append(strs[0]);
     * 换成
     * for(int i=strs.length-1;i>=0;i--){
     * sb.append(strs[i]+" ");
     * }
     * sb就会在字符串结尾多出一个空格,要去掉的
     *
     */}
      

  11.   

    楼上的, 楼主给的 字符串语法不对。 如果是 i'm fine ,反转后应该是 fine i'm, 你这个匹配好像就不能用了。
      

  12.   

    补充一下结果:
    ! hao jia da     Word Hello
      

  13.   

    带有
    new StringBuilder(str).reverse().toString()
    的都不对
      

  14.   

    如果'号不当成标点.你就把String regex="[^\\w]"改为:
    String regex="[^\\w']"
      

  15.   

    我做的。例:String str1 = "nice to meet you!";
              打印出的结果是:ecin ot teem !uoy (控制每个单词reverse)public class Test {
    public static void main(String[] args) {
    String str1 = "nice to meet you!";
    String [] a = str1.split(" ");
    changeArray(a);
    }
    public static void changeArray(String []a){
    for(int i = 0; i < a.length; i++){
    System.out.print(changeString(a[i])+" ");
    }
    }
    public static String changeString(String str){
    char []b = str.toCharArray();
    String str1 = "";
    for(int i =b.length - 1 ; i >= 0 ; i-- ){
    str1 = str1 + b[i];
    }
    return str1;
    }
    }