Contoh Tipe Data dan Variabel Di Java

1. Buat program berikut dengan nama file KelasVariabel.java :

public class KelasVariabel {
    
    public static void main(String args[]) {
    
        // Kelas Boolean
        System.out.println(" ====== Kelas Boolean ====== ");
        Boolean myBool1 = new Boolean(true);
        Boolean myBool2 = new Boolean("false");
        
        System.out.println("Nilai variabel Boolean ke-1 =" + myBool1.booleanValue());
        System.out.println("Nilai variabel Boolean ke-2 =" + myBool2.toString() + "\n");

        // Kelas Byte
        System.out.println(" ====== Kelas Byte ====== ");
        Byte myByte = new Byte("4");
        
        System.out.println("Nilai variabel Byte = " +myByte.toString());
        System.out.println("Nilai maks variabel Byte = "+ myByte.MAX_VALUE);
        System.out.println("Nilai min variabel Byte = " +myByte.MIN_VALUE + "\n");

        // Kelas Short
        System.out.println(" ====== Kelas Short ====== ");
        Short myShort = new Short("15");
        
        System.out.println("Nilai variabel Short = " + myShort.toString());
        System.out.println("Nilai maks variabel Short = "+ myShort.MAX_VALUE);
        System.out.println("Nilai min variabel Short = "+ myShort.MIN_VALUE + "\n");

        // Kelas Integer
        System.out.println(" ====== Kelas Integer ====== ");
        Integer myInt1 = new Integer("15");
        Integer myInt2 = new Integer("80");

        System.out.println("Nilai integer ke-1 = " + myInt1.toString());
        System.out.println("Nilai integer ke-2 = " + myInt2.toString());
        System.out.println("Nilai maks integer = " + myInt1.MAX_VALUE);
        System.out.println("Nilai min integer = " + myInt1.MIN_VALUE);
        System.out.println("Integer1 + Integer2 = " +(myInt1.intValue() + myInt2.intValue()) + "\n");

        // Kelas Character
        System.out.println(" ====== Kelas Character ====== ");
        Character myChar1 = new Character('X');
        Character myChar2 = new Character('\uaaaa');

        System.out.println("Nilai character ke-1 = " + myChar1.charValue());
        System.out.println("Nilai character ke-2 = " + myChar2.charValue() + "\n");

        // Kelas Float
        System.out.println(" ====== Kelas Float ====== ");
        Float myFloat = new Float(8004.15);

        System.out.println("Nilai variabel Float = " +myFloat.toString());
        System.out.println("Nilai maks Float = " + myFloat.MAX_VALUE);
        System.out.println("Nilai min Float = " + myFloat.MIN_VALUE + "\n");

        // Kelas Double
        System.out.println(" ====== Kelas Double ====== ");
        Double myDouble = new Double(15e4);
        
        System.out.println("Nilai variabel Double = " + myDouble.toString());
        System.out.println("Nilai maks Double = " + myDouble.MAX_VALUE);
        System.out.println("Nilai min Double = " + myDouble.MIN_VALUE + "\n");
        
    }
}

Comments

Anonymous said…
Makasih gan sudah berbagi...

Popular posts from this blog

Tipe File dan Macam - Macam File

Model Warna YIQ