JAVA 输入一个字符串,将大写字母改成小写,小写字母改成大写

JAVA 输入一个字符串,将大写字母改成小写,小写字母改成大写

public class Homework3 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(“请输入字符串:”);
String character = sc.nextLine();
char[] arr=character.toCharArray();
for (int i = 0; i < arr.length; i++) {
if ((int)arr[i] >= 65 && (int)arr[i] <= 90) {
arr[i] += 32;
} else if ((int)arr[i] >= 97 && (int)arr[i] <= 122) {
arr[i] -= 32;
}
}
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]+" ");
}
}
}

你可能感兴趣的:(java)