反转字符串. 字符串和数组可以转换...
String s1 = "hello,world";
// 反转后."dlrow,olleh"
char[] ch = s1.toCharArray();
System.out.println(Arrays.toString(ch));
int start = 0;
int end = ch.length - 1;
while (start < end) {
char temp = ch[start];
ch[start] = ch[end];
ch[end] = temp;
start++;
end--;
}
System.out.println(new String(ch)); |
|