呵呵,请帮忙检查一下代码的安全性,以及给点建议优化一下。
2008-04-04 09:36
441 查看
import java.lang.NumberFormatException;
import javax.swing.JOptionPane;
public class StudentGrade {
private static String b = null;
public static void main(String[] args){
StudentGrade sd=new StudentGrade();
System.out.println("你的考试级别为:"+sd.AboutLever());
}
public String AboutLever() throws NumberFormatException
{
String Lever = null;
try{
b=JOptionPane.showInputDialog("请输入您的成绩:");
int a=(Integer.valueOf(b)).intValue();
if(a>100 || a<0){
JOptionPane.showMessageDialog(null,"输入成绩错误! 程序退出!");
System.exit(0);
}
else{
a=a/10;
}
switch (a){
case 10:
case 9:
Lever="优秀";
break;
case 8:
Lever="良好";
break;
case 7:
Lever="中等";
break;
case 6:
Lever="及格";
break;
default:
Lever="不及格";
}
}catch(NumberFormatException ne){
JOptionPane.showMessageDialog(null,"请您输入数字!");
System.exit(0);
}
return Lever;
}
}
import javax.swing.JOptionPane;
public class StudentGrade {
private static String b = null;
public static void main(String[] args){
StudentGrade sd=new StudentGrade();
System.out.println("你的考试级别为:"+sd.AboutLever());
}
public String AboutLever() throws NumberFormatException
{
String Lever = null;
try{
b=JOptionPane.showInputDialog("请输入您的成绩:");
int a=(Integer.valueOf(b)).intValue();
if(a>100 || a<0){
JOptionPane.showMessageDialog(null,"输入成绩错误! 程序退出!");
System.exit(0);
}
else{
a=a/10;
}
switch (a){
case 10:
case 9:
Lever="优秀";
break;
case 8:
Lever="良好";
break;
case 7:
Lever="中等";
break;
case 6:
Lever="及格";
break;
default:
Lever="不及格";
}
}catch(NumberFormatException ne){
JOptionPane.showMessageDialog(null,"请您输入数字!");
System.exit(0);
}
return Lever;
}
}
相关文章推荐
- 请朋友帮忙优化一下下面的代码,降低其时间复杂度。。。
- SQL Server 海量数据查询代码优化以及建议
- SQL Server 海量数据查询代码优化以及建议
- SQL Server 海量数据查询代码优化以及建议
- SQL Server 海量数据查询代码优化以及建议
- 优化PHP代码的40条建议
- 关于 Unity Profiler 的使用以及代码建议
- 给php程序员的40条建议 优化你的php代码(一)【转载】
- 当js操作dom元素时,遇到undefined时,要检查一下js代码与html元素的位置
- python密码安全性检查代码
- 44条Java代码优化建议
- php代码安全性的建议
- 优化PHP代码的40条建议
- C#检查HTML是否闭合以及自动修复代码
- Xcode Analyze进行代码静态检查以及一些常见问题释疑
- 优化PHP代码的40条建议
- OpenCV:Mat元素访问方法、性能、代码复杂度以及安全性分析
- 优化 PHP 代码建议
- web代码发布脚本以及优化1.0