[Java] 纯文本查看 复制代码 public static String reverse(String str) {
char[] chs = str.toCharArray();
int start = 0;
int end = chs.length - 1;
while(start < end) {
ArrayUtil.swap(chs, start, end);
start += 1;
end -= 1;
}
return String.valueOf(chs);
}
测试代码及输出:
[Java] 纯文本查看 复制代码 Log.debugVals(reverse("12345"));
Log.debugVals(reverse("123456"));
Log.debugVals(reverse("大家好"));
[Java] 纯文本查看 复制代码 [00:00:00] [DEBUG]: ["54321"]
[00:00:00] [DEBUG]: ["654321"]
[00:00:00] [DEBUG]: ["好家大"]
|