Java 정수형, 실수형 데이터타입의 저장 가능한 범위

munilive
Written by munilive on (Updated: )

Java에서 사용되는 DataType 기본형 중에 정수형과 실수형의 자료 범위표 이다.

DataTypeByteMinMax
byte1byte-128127
short2byte-3276832767
int4byte-21474836482147483647
long8byte-92233720368547758089223372036854775807
float4byte1.4E-453.4028235E38
double8byte4.9E-3241.7976931348623157E308

아래 코드는 위 표에서 설명하는 Min/Max에 해당하는 범위를 Java에서 직접 출력하기 위한 예제 코드이며, 그 결과를 아래 첨부하였다.

//자료형별 최대값 최소값
public class MinAndMax {
    public static void main(String[] args) {
        System.err.println("byte의 최소값 : " + Byte.MIN_VALUE);
        System.err.println("byte의 최대값 : " + Byte.MAX_VALUE);

        System.err.println("short의 최소값 : " + Short.MIN_VALUE);
        System.err.println("short의 최대값 : " + Short.MAX_VALUE);

        System.err.println("int의 최소값 : " + Integer.MIN_VALUE);
        System.err.println("int의 최대값 : " + Integer.MAX_VALUE);

        System.err.println("long의 최소값 : " + Long.MIN_VALUE);
        System.err.println("long의 최대값 : " + Long.MAX_VALUE);

        System.err.println("float의 최소값 : " + Float.MIN_VALUE);
        System.err.println("float의 최대값 : " + Float.MAX_VALUE);

        System.err.println("double의 최소값 : " + Double.MIN_VALUE);
        System.err.println("double의 최대값 : " + Double.MAX_VALUE);
    }
}

소스 출력결과

소스 출력결과

Comments

comments powered by Disqus