在java中如何把一个字符串返序输出?

一个字符串hello world
把这个字符串倒着输出来是dlrow olleh

第1个回答  推荐于2016-06-25
public class Test{
public static void main(String[] args){
String str="hello world";
for(int i=str.length()-1;i>=0;i--){
System.out.print(str.charAt(i));
}
}
}本回答被提问者采纳
第2个回答  2008-11-29
或者利用StringBuffer里的reverse()函数:
public class Test{
public static void main(String[] args){
String s = "abcdefg";
StringBuffer sb = new StringBuffer(s);
System.out.println(sb.reverse());
}
}
相似回答