Java Ch 8 예외처리

Java Ch 8 예외처리

public class Ex8_2와3예외처리구문추가 {

public static void main(String[] args) {

int number = 100;

int result = 0;

// for (int i=0; i<10; i++){

// result = number/(int)(Math.random()*10);

// System.out.println(result);

// }

// }

// } //원래 코드

for (int i = 0; i < 10; i++) {

try {

result = number / (int) (Math.random() * 10);

System.out.println(result);

} catch (ArithmeticException e) {

System.out.println("0");

}

}

}

}

//Exception in thread "main" java.lang.ArithmeticException 산술연산과정에서 오류가 있을 떄 발생하는 예외

from http://ing-til-death.tistory.com/45 by ccl(A) rewrite - 2021-09-10 18:26:56