-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTypeCasting.java
More file actions
41 lines (34 loc) · 991 Bytes
/
Copy pathTypeCasting.java
File metadata and controls
41 lines (34 loc) · 991 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class TypeCasting {
public static void main(String[] args) {
// widening casting (otomatis)
// narrowing casting (eksplisit / manual)
// byte - short - int - long - float - double
// long nilaiKita = 12;
// byte nilaiHasil = (byte) nilaiKita;
// System.out.println(nilaiHasil);
// double hitung = -9.8;
// int angka = (int) hitung;
// System.out.println(angka);
// double nilai = 200.5631;
// int hasil = (int) nilai;
// int angka = 130;
// byte hasil = (byte) angka;
//
// System.out.println(hasil);
// 130
// 10000010
// 10000010
// -126
// int angka = 256;
// byte hasil = (byte) angka;
//
// System.out.println(hasil);
// long angka = 123456789L;
// float hasil = angka;
// char huruf = 'A';
// int kodeHuruf = huruf;
// System.out.println(kodeHuruf);
// char huruf = (char) 65;
// System.out.println("nilai 65 dari char adalah: " + huruf);
}
}