nme.kr

문서의 이전 판입니다!


chaptor 3

package chapter03;

public class CastingEx {

	public static void main(String[] args) {
		
		// 자동형변환 예시
		int number = 10;	// int 자료형
		
		long number2 = number;	// 자동형변환 int < long
		
		System.out.println(number2);
		
	}
}

package chapter03;

public class CastingEx2 {

	public static void main(String[] args) {
		
		// 강제형변환 예시
		double pi = 3.14;	// double 자료형
		
		int pi2 = (int)pi;	// 강제형변환
		
		System.out.println(pi2); // 값의 손실 발생
	}
}

package chapter03;

public class CastingEx3 {

	public static void main(String[] args) {
		
		// 강제형변환 예시
		double score = 100;	// double 자료형
		
		int score2 = (int)score;	// 강제형변환
		
		System.out.println(score2); // 값의 손실 발생하지 않음
	}
}

package chapter03;

public class CharType {

	public static void main(String[] args) {
		
		char a = 'A';
		
		System.out.println("a:"+a);
		
		int b = a;
		System.out.println("b:"+b);
		
		char c = 66;
		System.out.println("c:"+c);
		
		int d = a+b; // 65 + 65
		System.out.println("d:"+d);

	}

}

package chapter03;

public class Excercise {

	public static void main(String[] args) {
		
		//int c = 'A';
		
		
//		int a = 3.14;
//		int b = 3f;
//		float c = 3d;
//		double d = 3L;
		
		double a = 3.141562;
		int b = (int)a;
		System.out.println(b);

	}

}