- Scanner scanner = new Scanner(System.in);
- String string = scanner.nextLine();
- char[] c = string.toCharArray();
- for (int i = 0; i < c.length; i++) {
- if (c[i] <= 'z' && c[i] >= 'a') {
- c[i] -= 32;
- } else if (c[i] <= 'Z' && c[i] >= 'A') {
- c[i] += 32;
- }
- }
- System.out.println(new String(c));
- scanner.close();
复制代码 |