public class jisuan {
public static void main(String[] args) {
int result;
Core core=new Core();
}
}
class Core{
String op;
String op2;
int a,b,c;
int result;
public int ji(int a,String op,int b,String op2,int c)throws yichang{
if(op.equals("+")){
result=a+b;
}
if(op.equals("-")){
result=a-b;
}
if(op.equals("*")){
result=a*b;
}
if(op.equals("/")){
try{
if(b==0){
throw new yichang();
}
}catch(yichang e){
e.chufa();
}finally{};
result=a/b;
}
else{
try{throw new yichang();}catch(yichang e){
e.leixing();
}finally{};

}
if(op2.equals("+")){
result=result+c;
}
if(op2.equals("-")){
result=result+c;
}
if(op2.equals("*")){
result=result*c;
}
if(op2.equals("/")){
try{
if(c==0){
throw new yichang();
}
}catch(yichang e){
e.chufa();
}finally{};
result=result/c;
}
else {
try{
throw new yichang();
}catch(yichang e){
e.leixing();
}finally{};
}
return result;
}
}
class yichang extends Exception{
public void chufa(){
System.out.println("分母不能为0");
}
public void leixing(){
System.out.println("类型不对应");
}
}

相关文章:

  • 2021-08-31
  • 2021-07-20
  • 2022-12-23
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-17
猜你喜欢
  • 2021-07-02
  • 2021-10-18
  • 2021-10-27
  • 2021-04-15
  • 2021-11-15
  • 2022-01-27
  • 2021-12-08
相关资源
相似解决方案