📄 ex2.java
字号:
class Example{
static int result(int x, int y) throws ArithmeticException,Exception{
int a=0, b=0, c=0;
a=4*x-4;
b=2*x*x-4*x*y+y*y;
if(a==0 || b==0){
throw new ArithmeticException("A 或 B =0");
}
else if (a!=0 && b!=0){
throw new Exception("program is ok!");
}
c=a/b;
return c;
}
public static void main(String[] args){
int x=(int)(Math.random()*21);
int y=(int)(Math.random()*21);
try{
System.out.print("result("+x+" , " +y + " ) = ");
System.out.println("" +result(x,y));
}catch (ArithmeticException e){
System.out.println(e.getMessage());
}catch (Exception e){
System.out.println(e.getMessage());
}finally{
System.out.println("program is end");
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -