标签:
最近小伙伴去培训了,问到问题也给记录下来,温故知新。
1.Char和String的关系
/ System.out.println("请输入一个字母");
// Scanner sc = new Scanner(System.in);
// String str = sc.next();//获取得到到字符串
// String s=str.toLowerCase();//字符串转换为小写
// char c = s.charAt(0);
// System.out.println(c);
@SuppressWarnings("resource")
Scanner in = new Scanner(System.in);
System.out.print("请输入字母:");
char c = in.next().charAt(0);
if (c >= ‘A‘ && c <= ‘Z‘) {
c += 32;
System.out.println("这里的大写" + (char) (c - 32) + "被转换成了" + c);
System.out.println("这里的大写" + (c - 32) + "被转换成了" + c);
} else if (c >= ‘a‘ && c <= ‘z‘) {
c -= 32;
System.out.println("这里的小写" + (char) (c + 32) + "被转换成了" + c);
System.out.println("这里的小写" + (c + 32) + "被转换成了" + c);
}
待续
标签:
原文地址:http://www.cnblogs.com/C3054/p/5530626.html