Contoh Penanganan Exception di Java
import java.util.*;
public class Main{
public static void main(String[] args){
int a;
int b;
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
int c;
try{
c = a/b;
System.out.println(c);
}catch(ArithmeticException e){
System.out.println("Divide by zero");
}
}
}
Komentar
Posting Komentar