提示: a~z的ASCII码:97~122
A~Z的ASCII码:65~90
代码:
public static void main(String[] args) {
System.out.println("请输入一个大写字母或者小写字母:");
Scanner sc = new Scanner(System.in);
String str = sc.next();
//charAt(0):将你输出的字符串字母转换为字符,
// 并经过自动类型转换直接赋值给int类型的变量
int num = str.charAt(0);
if (num >= 65 && num <= 90) {
char upperCaseLetters = (char) (num + 32);
System.out.println(upperCaseLetters);
} else {
char lowerCaseLetters = (char) (num - 32);
System.out.println(lowerCaseLetters);
}
sc.close();
}
运行结果