자바
[JAVA] Char to Int 문자형 정수형으로 변환
배게
2018. 4. 26. 04:19
728x90
Char - '0'을 이용하면 int형으로 변환이 가능하다.
Character.getNumervalue(input.charAt(i)) 를 이용해도 형변환이 가능하나
위의 방법이 훨씬 편하다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | public class baekjoon { public static void main(String[] args) { char ch_int; int real_int; ch_int = '3'; real_int = 3; if ( ch_int == real_int) System.out.println("아직은 다르다"); else if ( ch_int-'0' == real_int) System.out.println("같다"); } } |
결과 : 같다