使用JAVA编写一个程序,接收用户输入的英文字符,将大写转换为小写输出,将小写转换为大写输出。

如题所述

import java.util.Scanner;public class A04 {
public static void main(String args[]) {
System.out.println("请输入字符串:");
String s = new Scanner(System.in).next(); System.out.println("输出结果:");
for (char c : s.toCharArray()) {
if (c >= 'a' && c <= 'z') {
c -= 32;
} else if (c >= 'A' && c <= 'Z') {
c += 32;
}
System.out.print(c);
} }
}
温馨提示:答案为网友推荐,仅供参考