본문 바로가기
오류

integer.parseInt null

by 신방동불주먹 2022. 12. 12.

case1. 숫자로 변경할시 숫자형이 아닌 문자열일 경우

String codeB = "123o"; // 문자형 변수 codeB 에 문자 123O을 입력 123 + O(알파벳 대문자 O)

System.out.println(Integer.parseInt(codeB)) // 정수아닌 문자가 포함되어 에러발생

 

case2. 변경하는 자료형보다 범위가 큰경우

String codeC = "123123123123123123123123";

System.out.println(Integer.parseInt(codeC)) // int 범위보다 큰 정수여서 에러발생

 

case3. null 입력시

String codeD = null;

System.out.println(Integer.parseInt(codeD)) // null을 변환시키려고 해서 에러발생

 

case4. 문자 앞뒤로 공백이 있는경우

String codeE = " 123 ";

System.out.println(Integer.parseInt(codeE)) // 123 문자열 앞뒤에 공백이 있어서 에러발생