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);
23115.0 4567.0 678.0 78.0 68.0
} }
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);