|
package xiangmu;
|
|
|
|
import java.util.Scanner;
|
|
|
|
public class Ceshi {
|
|
public static void main(String args[]) {
|
|
/* 用户输入一个字母,
|
|
* 如果是大写字母,程序自动转化成小写字母并输出;
|
|
* 如果是小写字母,程序自动转化成大写字母并输出
|
|
*/
|
|
System.out.print("请输入一个字母:");
|
|
Scanner sc = new Scanner(System.in);
|
|
char zifu = sc.next().charAt(0); // 获取用户输入的单个字符
|
|
if (zifu >= 'A' && zifu <= 'Z') {
|
|
zifu = (char)(zifu + 32);
|
|
System.out.println("转化成小写字母为:" + zifu);
|
|
}else if(zifu >= 'a' && zifu <= 'z') {
|
|
zifu = (char)(zifu - 32);
|
|
System.out.println("转化成大写字母为:" + zifu);
|
|
}else {
|
|
System.out.println("非法字符!");
|
|
}
|
|
sc.close();
|
|
}
|
|
}
|