[Java] 자바 문자를 숫자로 바꾸기 (char to int)
·
Language/Java
처음에는 문자(char)를 숫자(int)로 바꿀 때 문자열(String)과 차이가 없는 줄 알고 Integer.parseInt()를 썼더니 아래와 같은 에러가 떴다.Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method parseInt(String) in the type Integer is not applicable for the arguments (char) String을 int형으로 바꿀 때는 Integer.parseInt()를 쓰지만, char를 int형으로 바꿀 때는 아래의 두 가지 방법을 사용한다. Solution 1char c = '1';int n = c - '0'; // 1'0'의 아스키코드..