package day20;
public class NoCodeException extends Exception{
public NoCodeException(){
}
public NoCodeException(String msg){
super (msg);
}
}
package day20;
public class Sample18 {
public static int findGrade(double code)throws NoCodeException {
//
if (code >=0 && code<65){
return 5;
}
if (code >=65 && code<75){
return 4;
}
if (code >=75 && code < 85){
return 3;
}
if (code >=85 && code <=100){
return 1;
}
else{
throw new NoCodeException("不及格:"+ code +"!!!");
}
}
public static void main(String[] args) {
//
try{
int grade = findGrade(67);
System.out.println("67:" + grade +"。");
grade = findGrade(-20);
System.out.println("-20:" + grade +"。");
}
//
catch(NoCodeException e){
e.printStackTrace();
}
}
}
|
|