Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
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
Tags
more
Archives
Today
Total
관리 메뉴

WON.dev

chapter03 : exception 본문

JAVA/chapter19_exception

chapter03 : exception

GAWON 2023. 5. 30. 09:28
package org.joonzis.ex;
/*
 * NumberFormatException
 * 주어진 문자열을 정수 및 실수로 변환하지 못할 경우 예외 발생
 */
public class Ex03_exception {
	public static void main(String[] args) {
		
		String data1 = "100";
		String data2 = "100a";
		
		// 위 변수 데이터를 파싱하여 숫자로 출력
		// 첫 번째 변환한 값 : 
		// 두 번째 변환한 값 :
		// 출력
		// 예외 발생 시 "문자열을 숫자로 변환할 수 없습니다." 출력
		try {
			int val1 = Integer.parseInt(data1);
			System.out.println("첫 번째 변환한 값 : " + val1);
			int val2 = Integer.parseInt(data2);
			System.out.println("두 번째 변환한 값 : " + val2);
		} catch (NumberFormatException e) {
			System.out.println("문자열을 숫자로 변환할 수 없습니다.");
		}
		
		
		
	}
}

'JAVA > chapter19_exception' 카테고리의 다른 글

chapter06 : exception  (0) 2023.05.30
chapter05 : exception  (0) 2023.05.30
chapter04 : exception  (0) 2023.05.30
chapter02 : exception  (0) 2023.05.30
chapter01 : exception  (0) 2023.05.30