错在何处
import java.util.*;
public class Grade{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
System.out.println("请输入等级:");
String grade=in.nextLine();
switch(grade){
case"A":System.out.println(grade+"is 85~100");
break;
case"B":System.out.println(grade+"is 70~84");
break;
case"C":System.out.println(grade+"is 60~69");
break;
case"D":System.out.println(grade+"is<60") ;
break;
default:System.out.println("input error");
}
}
}
错在何处。。
------解决方案--------------------case"A" jdk1.7貌似才支持String可以修改case 'A'
------解决方案--------------------貌似没错
------解决方案--------------------Java code
import java.util.*;
public class Grade {
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.println("请输入等级:");
String grade = in.nextLine();
switch (grade.charAt(0)) {
case 'A':
System.out.println(grade + "is 85~100");
break;
case 'B':
System.out.println(grade + "is 70~84");
break;
case 'C':
System.out.println(grade + "is 60~69");
break;
case 'D':
System.out.println(grade + "is<60");
break;
default:
System.out.println("input error");
}
}
}