⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex2.java

📁 我在学习JAVA的讲义
💻 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 + -