Anda di halaman 1dari 6

Membuat formulasi proses casting dari tipe-tipe primitif

Asal boolean char byte short int long float double


double 12.0988 - 12 12 12 12 12.0988 12.0988
Float 135.086 - ? - 135 135 135 135.086 135.08599853515625
121
Long 23115 - ? 75 23115 23115 23115 23115.0 23115.0
Int 4567 - ? -41 4567 4567 4567 4567.0 4567.0
Short 678 - ? -90 678 678 678 678.0 678.0
Byte 78 - N 78 78 78 78 78.0 78.0
char D - D 68 68 68 68 68.0 68.0
boolean

public class Casting {

public static void main(String args[]) {

double d = 12.0988;

float f = (float) d;

long l = (long) d;

int i = (int) d;

short s = (short) d;

byte bt = (byte) d;

char c = (char) d;

System.out.println("Nilai d = " + d);

System.out.println("Konversi d ke c = " + c);

System.out.println("Konversi d ke bt = " + bt);

System.out.println("Konversi d ke s = " + s);

System.out.println("Konversi d ke i = " + i);

System.out.println("Konversi d ke l = " + l);

System.out.println("Konversi d ke f = " + f);


}

public class Casting {

public static void main(String args[]) {

float f = 135.086F;

double d = (double) f;

long l = (long) f;

int i = (int) f;

short s = (short) f;

byte bt = (byte) f;

char c = (char) f;

System.out.println("Nilai f = " + f);

System.out.println("Konversi f ke c = " + c);

System.out.println("Konversi f ke bt = " + bt);

System.out.println("Konversi f ke s = " + s);

System.out.println("Konversi f ke i = " + i);

System.out.println("Konversi f ke l = " + l);

System.out.println("Konversi f ke d = " + d);


}

public class Casting {

public static void main(String args[]) {

long l = 23115l;

float f = (float) l;

double d = (double) l;

int i = (int) l;

short s = (short) l;

byte bt = (byte) l;

char c = (char) l;

System.out.println("Nilai l = " + l);

System.out.println("Konversi l ke c = " + c);

System.out.println("Konversi l ke bt = " + bt);

System.out.println("Konversi l ke s = " + s);

System.out.println("Konversi l ke i = " + i);

System.out.println("Konversi l ke f = " + f);

System.out.println("Konversi l ke d = " + d);

}
}

public class Casting {

public static void main(String args[]) {

int i = 4567;

long l = (long) i;

float f = (float) i;

double d = (double) i;

short s = (short) i;

byte bt = (byte) i;

char c = (char) i;

System.out.println("Nilai i = " + i);

System.out.println("Konversi i ke c = " + c);

System.out.println("Konversi i ke bt = " + bt);

System.out.println("Konversi i ke s = " + s);

System.out.println("Konversi i ke l = " + l);

System.out.println("Konversi i ke f = " + f);

System.out.println("Konversi i ke d = " + d);

}
public class Casting {

public static void main(String args[]) {

byte bt = 78;

short s = (short) bt;

int i = (int) bt;

long l = (long) bt;

float f = (float) bt;

double d = (double) bt;

char c = (char) bt;

System.out.println("Nilai bt = " + bt);

System.out.println("Konversi bt ke c = " + c);

System.out.println("Konversi bt ke s = " + s);

System.out.println("Konversi bt ke i = " + i);

System.out.println("Konversi bt ke l = " + l);

System.out.println("Konversi bt ke f = " + f);

System.out.println("Konversi bt ke d = " + d);

public class Casting {


public static void main(String args[]) {

char c = 'D';

byte bt = (byte) c;

short s = (short) c;

int i = (int) c;

long l = (long) c;

float f = (float) c;

double d = (double) c;

System.out.println("Nilai c = " + c);

System.out.println("Konversi c ke bt = " + bt);

System.out.println("Konversi c ke s = " + s);

System.out.println("Konversi c ke i = " + i);

System.out.println("Konversi c ke l = " + l);

System.out.println("Konversi c ke f = " + f);

System.out.println("Konversi c ke d = " + d);