您的位置:首页 > 编程语言

呵呵,请帮忙检查一下代码的安全性,以及给点建议优化一下。

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;
 }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  优化 string null import class