Java言語数字の基本型

2008/10/10 15:44Update
TAGS: Java | 数字 | byte | char | short | int | long | float | double

数字を表すJavaの基本型であるbyteやchar、short、int、long、float、doubleについて学びます。


■byte
符号付byte(バイト)型(符号は1ビットになります)
◇長さ:1バイト(8ビット)
◇範囲:[-2^7, 2^7-1] = [-128, 127]
◇定義:
        byte b1 = 'B';
        byte b2 = 123;
        byte b3 = -123;

■char
符号なしchar(キャラ)型
◇長さ:2バイト(16ビット)
◇範囲:[0, 2^16-1] = [0, 65535]
◇定義:
        char c1 = 0;
        char c2 = 65535;

■short
符号付短整数型
◇長さ:2バイト(16ビット)
◇範囲:[-2^15, 2^15-1] = [-32768, 32767]
◇定義:
        short s1 = -32768;
        short s2 = 32767;

■int
符号付整数型
◇長さ:4バイト(32ビット)
◇範囲:[-2^31, 2^31-1] = [-2147483648, 2147483647]
◇定義:
        int i1 = 5;     //正の整数
        int i2 = -5;    //負の整数

■long
符号付長整数型
◇長さ:8バイト(64ビット)
◇範囲:[-2^63, 2^63-1]
◇定義:
        long l1 = 5;
        long l2 = 5l;
        long l3 = 5L;

■float
32ビット浮動小数点数型
◇長さ:4バイト(32ビット)
◇範囲:[1.401298E-045F, 3.402823E+038F]
◇定義:
        float f1 = 1;
        float f2 = 1.0f;
        float f3 = 1.0F;
        float f4 = -1.0F;


■double
64ビット浮動小数点数型
◇長さ:8バイト(64ビット)
◇範囲:[4.9406564584124654E-324D, 1.7976931348623157E+308D]
◇定義:
        double d1 = 1.0;
        double d2 = 1.0d;
        double d3 = 1.0D;
        double d4 = -1.0D;

有关作者
Syboos.jp編集長AJavaやオープンソース情報の執筆、Webサイトの開発や運営全般の業務に携わる。

Sponsored Link


Comments

用户名 (required)

Email (will not be published) (required)

URL

Evaluation