package Test4;
public class Test04 {
public static void main(String[] args) {
// 创建一个字符串对象
String s = "HelloWorld";
// 将字符串转换成字符数组
char[] cha = s.toCharArray();
StringBuffer sb = new StringBuffer();
// 遍历数组并转换每个字符,
for (int x = cha.length - 1; x >= 0; x--) {
if (cha[x] >= 'A' && cha[x] <= 'Z') {
sb.append(String.valueOf(cha[x]).toLowerCase());
} else {
sb.append(String.valueOf(cha[x]).toUpperCase());
}
}
System.out.println(sb.toString());
}
}
|
|