본문 바로가기
IT/프로그래밍

JAVA 프로그래밍 기초부터 활용까지 2장 소스코드

by nutrient 2021. 5. 22.
728x90
728x170

 

//예제02-01 ByteTest.java
class ByteTest {
	public static void main(String args[]) {
		byte  byteVar1;

		byteVar1 = 128;
		System.out.println("byteVar1 = "+byteVar1);
	}
}

 

//예제02-02 ShortTest.java
class ShortTest {
	public static void main(String args[]) {
		short  shortVar1;

		shortVar1 = 128;
		System.out.println("shortVar1 = "+shortVar1);
	}
}

 

//예제02-03 FloatingTest.java
class  FloatingTest {
	public static void main(String args[]) {
		float   floatVar1;
		double  doubleVar1;

		//floatVar1 = 2.5; 이렇게 쓰면 2.5는 double type임으로 에러남
		floatVar1 = 2.5f;
		doubleVar1 = 2.5;

		System.out.println("floatVar1 = "+floatVar1);
		System.out.println("doubleVar1 = "+doubleVar1);

	}
}

 

//예제02-04 FloatingIntTest.java
class  FloatingIntTest {
	public static void main(String args[]) {
		int intVar1 =5, intVar2 =2;
		float   floatVar1 , floatVar2;

		floatVar1 = intVar1/intVar2;
        floatVar2 = (float)intVar1/intVar2;

		System.out.println("floatVar1 = "+floatVar1);
		System.out.println("floatVar2 = "+floatVar2);

	}
}

 

//예제02-05 CastingTest.java
class  CastingTest {
	public static void main(String args[]) {
		int intVar1 =5, intVar2 =2;
		float   floatVar1= 3.41f;
		
		System.out.println(1.0-intVar1+floatVar1+intVar2);

	}
}

 

//예제02-06 CharTest.java
class  CharTest {
	public static void main(String args[]) {
		char c = 'a';
	
		System.out.println(c);
		System.out.println((int)c);
	}
}

 

//예제02-07 BooleanTest.java
class  BooleanTest {
	public static void main(String args[]) {
		boolean x=true;

		System.out.println(x);
	}
}

 

//예제02-08 InitialTestLocal.java
class  InitialTestLocal {
	public static void main(String args[]) {
		boolean x=true;
		boolean y=false;

		System.out.println(x);
		System.out.println(y);
	}
}
728x90
그리드형

댓글