程序源代码:
package 课后作业;
import javax.swing.JOptionPane;
public class 课后作业 {
static String judge(int m)
{
String output="";
if(m<60)
{
output += "不及格";
}
if(m<70&&m>=60)
{
output +="及格";
}
if(m<80&&m>=70)
{
output +="良好";
}
if(m<90&&m>=80)
{
output +="中";
}
if(m<100&&m>=90)
{
output +="优秀";
}
return output;
}
public static void main(String[] args){
while(true)
{
try{
int m = 0;
String str=JOptionPane.showInputDialog("输入成绩");
m=Integer.parseInt(str);
if(m<0||m>100)
throw new Exception();
JOptionPane.showConfirmDialog(null,judge(m));
System.exit(0);
}
catch(Exception e)
{
JOptionPane.showConfirmDialog(null,"对不起,您输入的姿势不对,请重新输入");
}
}
}
}
程序结果截图:
原文:http://www.cnblogs.com/lvzaiyang/p/4967578.html