【发布时间】:2015-08-06 09:20:48
【问题描述】:
我发现了应该将第一个字符从小写字母更改为大写字母的语法。
由于某种原因,我的程序不会!当我输入“m”而不是“M”时。
我在这里做错了什么?
public static void main(String[] args) {
System.out.print("Enter two characters: ");
Scanner input = new Scanner(System.in);
String twoChar = input.nextLine();
if(twoChar.length() > 2 || twoChar.length() <= 1){
System.out.println("You must enter exactly two characters");
System.exit(1);
}
char ch = Character.toUpperCase(twoChar.charAt(0));
if(twoChar.charAt(0) == 'M'){
if(twoChar.charAt(1) == '1'){
System.out.println("Mathematics Freshman");
}else if(twoChar.charAt(1) == '2'){
System.out.println("Mathematics Sophomore");
}else if(twoChar.charAt(1) == '3'){
System.out.println("Mathematics Junior");
}else if(twoChar.charAt(1) == '4'){
System.out.println("Mathematics Senior");
}
}
【问题讨论】:
-
因为您复制了大写字符,然后针对原始字符进行测试。针对副本进行测试
ch。
标签: java string char uppercase lowercase