반응형

자바 기본 자료형 예제 

 

글. 오상문 sualchi@daum.net 

 

public class Main {
	public static void main(String[] args) {
		boolean bool = true; // 기본값은 false
		char ch = 'a';       // 기본값은 빈 문자
		byte by = 100;       // 기본값은 0
		short sh = 1000;
		int  i = 10000;
		long lo = 100000;
		float f = 10.5f;     // 기본값은 0.0
		double d = 100.5;
		String s = "strng";  // 기본값은 빈 문자열 
		System.out.println(bool);
		System.out.println(ch);
		System.out.println(by);
		System.out.println(sh);
		System.out.println(i);
		System.out.println(lo);
		System.out.println(f);
		System.out.println(d);
		System.out.println(s);
		for(char c='a'; c<='z';c++)
			System.out.print(c + " ");
		System.out.format("\n16진수: %#x\n", 255); // 0xff
		System.out.println(s.substring(0, 2));    // st		
	}
}

[실행결과]

true
a
100
1000
10000
100000
10.5
100.5
strng
a b c d e f g h i j k l m n o p q r s t u v w x y z 
16진수: 0xff
st

 

반응형

+ Recent posts