import javax.swing.JOptionPane;
public class switch_
{
public static void main(String args[])
{
String str;
int chengji;
str=JOtionPane.showInputDialog("输入成绩");
chengji=Integer.parseInt(str);
switch(chengji)
{
case 00-59: System.out.println("E级");break;
case 60-69: System.out.println("D级");break;
case 70-79: System.out.println("C级");break;
case 80-89: System.out.println("B级");break;
case 90-100: System.out.println("A级");break;
}
}
}
编译时出现 1 找不到符号位
2 case标签重复
------解决方案--------------------
- Java code
import javax.swing.JOptionPane; public class Test { public static void main(String args[]) { String str; int chengji; str=JOptionPane.showInputDialog("输入成绩"); //是JOptionPane类chengji=Integer.parseInt(str);chengji/=10; //修改switch(chengji) { case 6: System.out.println("D级");break; case 7: System.out.println("C级");break; case 8: System.out.println("B级");break; case 9: case 10: System.out.println("A级");break;default: System.out.println("E级");} } }