字符串反转
程序员文章站
2022-07-13 13:34:42
...
public class Fanzhuan {
public static void main(String[] args){
String str="xiaoxin";
System.out.print("xiaoxin的逆转的字符串:[");
for(int i=str.length()-1;i>=0;i--){
char ch = str.charAt(i);
System.out.print(ch);
}
System.out.print("]");
//II用字符串反转的命令
/*String str="good";
StringBuffer sb = new StringBuffer(str);
System.out.print("逆转后的字符串是:["+sb.reverse()+"]");*/
//III
/*String str="xiaoxin";
char s[] = str.toCharArray();
System.out.print("逆转的字符串:[");
for(int i=s.length-1;i >= 0;i--){
System.out.print(s[i]);
}
System.out.print("]");*/
}
}