-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtryexception.java
More file actions
33 lines (26 loc) · 959 Bytes
/
tryexception.java
File metadata and controls
33 lines (26 loc) · 959 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import java.util.Scanner;
public class tryexception {
public static void main(String [] args) {
/*try {
int [] angka = {32, 12, 50, 33};
System.out.println(angka[4]);
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Elemen array tidak ditemukan");
}*/
Scanner masuk = new Scanner(System.in);
float a, b, hasil = 0;
System.out.print("Bilangan Penyebut : ");
a = masuk.nextFloat();
System.out.print("Bilangan Pembilang : ");
b = masuk.nextFloat();
try {
hasil = a / b;
}catch(ArithmeticException e) {
System.out.println("Angka Tersebut Tidak Bisa Dibagi Dengan Nol");
}catch(Exception e) {
System.out.println(e.toString());
}finally {
System.out.println("Hasil : " + hasil);
}
}
}