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 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;

}

## 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;

}

## 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;

}
}

## 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("Konversi i ke d = " + d);

}
public class Casting {

byte bt = 78;

## 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("Konversi c ke d = " + d);

### Dapatkan aplikasi gratis kami

Hak cipta © 2021 Scribd Inc.