JAVA/예제

[JAVA] ch08-03. 예외 처리 3

밍글링글링 2017. 8. 22. 11:48
728x90
 
public class Ex03 {
    public static void main(String[] args) {
        int number = 100;
        int result = 0;
        
        for(int i = 0 ; i < 10 ; i++) {
            try{
                result = number / (int)(Math.random() * 10);
                System.out.println(result);
            }catch(ArithmeticException e){//RuntimeException, Exception 모두 사용 가능. 다형성 때문에
                System.out.println("0으로 나눌 수 없습니다.");
            }
        }
    }
}

728x90