day02_CastingEx2

육희영·2021년 9월 1일
0
package day02;

public class CastingEx2 {

	public static void main(String[] args) {
		/*
		 * 형변환(큰거에서 작은거로 변할때는 명시적으로 표현해줘야됨)
		 *  (작은거에서 큰거로 갈때는 자동형변환이 일어난다.)
		 */
		short s = 1;
		byte b = (byte) s;

		byte by = 1;
		short sh = by;

		// char 와 short는 둘다 2byte 타입
		char c = 65;
		short sht = (short) c;

		short shor = 65;
		char ch = (char) shor;

		// 작은범위에서 큰 범위로 갈때ㅑ 자동형변환
		int i = 1;
		long l = i;

		// 큰범위에서 작은 범위로 갈때는 명시적으로
		long lo = 1;
		int in = (int) lo;

		float f = 1.0f;
		double d = f;

       //작은범위에서 큰 범위로 갈때는 자동형변환
		double db1 = 1.0;
		float f1 = (float) db1;

	}

}

0개의 댓글

관련 채용 정보