가끔 코딩을 할때 입력받은 실수를 정수로 변환하거나 큰 정수형을 작은 정수형으로 변환이 필요할 때가 있죠? 그럴때 자바에서는 형을 변환시켜서 사용 합니다.
형 변환에는 명시적 형변환과 자동 형변환 2가지 방법이 있습니다. 간단하게 명시적 형 변환을 이용해 int형 변수에 실수의 값을 저장해 보겠습니다. 1 2 3 4 5 6 public class a1{ public static void main(String args[]){ int n = 2.0 * 3.0; System.out.println(n); } } Colored by Color Scripter cs Exception in thread "main" java.lang.Error: Unresolved compilation problem: Type mismatch: cannot convert from double to int at test.a1.main(a1.java:6) 저런 오류가 발생하고 말았습니다.
Type mismatch: ...
#
java
#
입력문
#
형변환
원문 링크 : [자바] 형변환 연산자