[Java] 자료형 (Data type)
boolean, byte, short, int, long, char, float, double, String
설명
참거짓 ( boolean )
boolean bool1 = true; // 1bit
System.out.printf(" Print bool1 : %b\n", bool1);
정수형 ( byte, short, int, long )
byte byte1 = 2; // 1 byte
short short1 = 4; // 2 byte
int int1 = 1; // 4 byte
long long1 = 9000000000000000000L; // 8 byte
System.out.printf(" Print byte1 : %d\n", byte1);
System.out.printf(" Print short1 : %d\n", short1);
System.out.printf(" Print int1 : %d\n", int1);
System.out.printf(" Print long1 : %d\n", long1);
문자형 ( char )
char char1 = 68; // 2 byte
char char2 = 'a'; // 2 byte
System.out.printf(" Print char1 : %c\n", char1);
System.out.printf(" Print char2 : %c\n", char2);
System.out.printf(" Print char1 : %d\n", (int)char1); // ASCII code
System.out.printf(" Print char2 : %d\n", (int)char2); // ASCII code
실수형 ( float, double )
float float1 = 9.0f; // 4 byte
double double1 = 5.0; // 8 byte
System.out.printf(" Print float1 : %.2f\n", float1);
System.out.printf(" Print double1 : %.3f\n", double1);
문자열 ( String )
System.out.printf(" Print str1 : %s\n", str1);
정리
728x90
댓글