정수 자료형

<aside> 💡

자바의 정수를 표현하기 위한 자료형은 대표적으로 int, long 이 있다. (byte, short 도 있지만 잘 사용하지 않는다.)

</aside>

type byte bit MIN_VALUE MAX_VALUE
byte 1 byte 8 bit -128 127
short 2 byte 16 bit -32768 32767
int 4 byte 32 bit -2147483648 2147483647 기본형(float와 메모리 사이즈 같음)
long 8 byte 64 bit -9223372036854775808 9223372036854775807 long사용 시에는 식별자L,l을 사용하는 숫자 뒤에 붙인다.

byte test

package datatype;

public class ByteTest {
	
	public static void main(String[] args) {
		//btye -> 관리하는 클래스를 만들었어요
		//java.lang.Byte num;
		System.out.print("byte의 최소값 : ");
		System.out.println(Byte.MIN_VALUE);
		System.out.printf("byte의 최대값 : %d\\n", Byte.MAX_VALUE);
		System.out.println("byte의 사이즈 : "+Byte.SIZE+" bit");
		System.out.println("byte의 byte : "+Byte.BYTES+" byte");
	}
}

short test

package datatype;

public class ShortTest {
	
	public static void main(String[] args) {
		//short -> 관리하는 클래스를 만들었어요
		//java.lang.Short num;
		
		System.out.print("short의 최소값 : ");
		System.out.println(Short.MIN_VALUE);
		System.out.printf("short의 최대값 : %d\\n", Short.MAX_VALUE);
		System.out.println("short의 사이즈 : "+Short.SIZE+" bit");
		System.out.println("short의 byte : "+Short.BYTES+" byte");
	}
}

int test

package datatype;

public class IntTest {
	
	public static void main(String[] args) {
		//int -> 관리하는 클래스를 만들었어요
		//java.lang.Integer num;
		
		System.out.print("int의 최소값 : ");
		System.out.println(Integer.MIN_VALUE);
		System.out.printf("int의 최대값 : %d\\n", Integer.MAX_VALUE);
		System.out.println("int의 사이즈 : "+Integer.SIZE+" bit");
		System.out.println("int의 byte : "+Integer.BYTES+" byte");
	}
}

long test

package datatype;

public class LongTest {
	
	public static void main(String[] args) {
		//long -> 관리하는 클래스를 만들었어요
		//java.lang.Long num;
		
		System.out.print("long의 최소값 : ");
		System.out.println(Long.MIN_VALUE);
		System.out.printf("long의 최대값 : %d\\n", Long.MAX_VALUE);
		System.out.println("long의 사이즈 : "+Long.SIZE+" bit");
		System.out.println("long의 byte : "+Long.BYTES+" byte");
	}
}