day19_ExceptionEx3

육희영·2021년 10월 28일
0

산술 연산과정에서 오류가 있을때 발생하는 예외(랜덤값)

package com.java1.day19;


//ArithmeticException은 산술 연산과정에서 오류가 있을때 발생하는 예외이다.
public class ExceptionEx3 {
	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) {
				System.out.println("0"); //ArithmeticException 이 발생하면 실행되는 코드..
			}
		}
	}
}

출력결과

16
14
12
14
50
14
25
12
0
50

0개의 댓글

관련 채용 정보