用java编写异常
发布网友
发布时间:2022-07-13 17:10
我来回答
共2个回答
热心网友
时间:2023-11-07 14:06
public class NoOprandException{
String a;
String b;
public NoOprandException(String a,String b){
this.a=a;
this.b=b;
}
public String errorException(){
if((a==null&&a.equals(""))&&(b==null&&b.equals(""))){
return "NoOprand错误!";
}
return;
}
}
public class OnlyOneException{
String a;
String b;
public OnlyOneException(String a,String b){
this.a=a;
this.b=b;
}
public String errorException(){
if((a==null&&a.equals(""))||(b==null&&b.equals(""))){
return "OnlyOne错误!";
}
return;
}
}
public class a{
public static void main(String[] args){
Scanner scan1=new Scanner(System.in);
Scanner scan2=new Scanner(System.in);
String line1=scan1.nextLine();
String line2=scan2.nextLine();
try{
throw new OnlyOneException(line1,line2);
}catch(OnlyOneException e){
System.out.print(e);
System.out.exit(0);
}
try{
throw new NoOprandException(line1,line2);
}catch(NoOprandException e){
System.out.print(e);
System.out.exit(0);
}
}
}
热心网友
时间:2023-11-07 14:06
题目描述不清,无法解答。