继承与接口课后作业

编写一个程序,此程序在运行时要求用户输入一个 整数,代表某门课的考试成绩,程序接着给出“不及格”、“及格”、“中”、“良”、“优”的结论。 要求程序必须具备足够的健壮性,不管用户输入什 么样的内容,都不会崩溃。

代码:

//2015.11.12
package ba;
import javax.swing.JOptionPane;
public class TestGrade {

public static void main(String[] args) {
// TODO Auto-generated method stub

try
{
String
grade=JOptionPane.showInputDialog("please input the grades");
int g=Integer.parseInt(grade);
if(g>=0&&g<60)
{
JOptionPane.showMessageDialog(null, "该生考试成绩不及格");
}
else if(g>=60&&g<70)
{
JOptionPane.showMessageDialog(null, "该生考试成绩及格");

}
else if(g>=70&&g<80)
{
JOptionPane.showMessageDialog(null, "该生考试成绩中等");
}
else if(g>=80&&g<90)
{
JOptionPane.showMessageDialog(null, "该生考试成绩良好");
}
else if(g>=90&&g<=100)
{
JOptionPane.showMessageDialog(null, "该生考试成绩优秀");
}
else if(g<0||g>100)
{
JOptionPane.showMessageDialog(null, "用户输入不正确");
}
}
catch(Exception e)
{
JOptionPane.showMessageDialog(null, "输入不正确,请检查");
}
}

}

结果截图:

原文地址:https://www.cnblogs.com/jingjing0629/p/4964934.html