1. 程式人生 > >java22 2018-12-13作業

java22 2018-12-13作業

##1、編寫應用程式,從命令列傳入兩個整型數作為除數和被除數。要求程式中捕獲
NumberFormatException 異常和ArithmeticException 異常,
而且無論在哪種情況下,“總是被執行”這句話都會在控制檯輸出。 [必作題]
在命令列輸入不同的引數時能輸出如下各種結果:
1.1 在命令列輸入 java A 
1.2 在命令列輸入 java A 1 2 
1.3 在命令列輸入 java A 1 3a 
1.4 在命令列輸入 java A 1 0

public static void main(String[] args) {
		try
{ int x=Integer.parseInt(args[0]); int y=Integer.parseInt(args[1]); int z=x/y; System.out.println(z); }catch(NumberFormatException a) { throw a; }catch(ArithmeticException a) { throw a; }finally { System.out.println("總是被執行"); } }