-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDasar03_tipe_data.java
More file actions
executable file
·86 lines (72 loc) · 3.6 KB
/
Dasar03_tipe_data.java
File metadata and controls
executable file
·86 lines (72 loc) · 3.6 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
public class Dasar03_tipe_data {
public static void main(String[] args){
// tipe data di java:
// integer, byte, short, long, double, float, char, boolean
// integer (satuan)
int i = 10;
System.out.println("======INTEGER======");
System.out.println("nilai integer i = " + (i + 1));
System.out.println("Nilai max = " + Integer.MAX_VALUE);
System.out.println("Nilai min = " + Integer.MIN_VALUE);
System.out.println("Besar integer = " + Integer.BYTES + " bytes");
System.out.println("Besar integer = " + Integer.SIZE + " bit");
// byte (satuan)
byte b = 10;
System.out.println("\n======BYTE======");
System.out.println("nilai byte b = " + b);
System.out.println("Nilai max = " + Byte.MAX_VALUE);
System.out.println("Nilai min = " + Byte.MIN_VALUE);
System.out.println("Besar byte = " + Byte.BYTES + " bytes");
System.out.println("Besar byte = " + Byte.SIZE + " bit");
// short (satuan)
short s = 10;
System.out.println("\n======SHORT======");
System.out.println("nilai short s = " + s);
System.out.println("Nilai max = " + Short.MAX_VALUE);
System.out.println("Nilai min = " + Short.MIN_VALUE);
System.out.println("Besar short = " + Short.BYTES + " bytes");
System.out.println("Besar short = " + Short.SIZE + " bit");
// long (satuan)
// Penandaan untuk long bisa menggunakan L
long l = 10L;
System.out.println("\n======LONG======");
System.out.println("nilai long l = " + l);
System.out.println("Nilai max = " + Long.MAX_VALUE);
System.out.println("Nilai min = " + Long.MIN_VALUE);
System.out.println("Besar long = " + Long.BYTES + " bytes");
System.out.println("Besar long = " + Long.SIZE + " bit");
// double (koma, bilangan real)
// Penandaan untuk double bisa menggunakan d
double d = -10.5d;
System.out.println("\n======DOUBLE======");
System.out.println("nilai double d = " + d);
System.out.println("Nilai max = " + Double.MAX_VALUE);
System.out.println("Nilai min = " + Double.MIN_VALUE);
System.out.println("Besar double = " + Double.BYTES + " bytes");
System.out.println("Besar double = " + Double.SIZE + " bit");
// float (koma, bilangan real)
// Penandaan untuk float bisa menggunakan f
float f = -8.5f;
System.out.println("\n======FLOAT======");
System.out.println("nilai float f = " + f);
System.out.println("Nilai max = " + Float.MAX_VALUE);
System.out.println("Nilai min = " + Float.MIN_VALUE);
System.out.println("Besar float = " + Float.BYTES + " bytes");
System.out.println("Besar float = " + Float.SIZE + " bit");
// char (karakter) berdasarkan ASCIICODE
char c = 'c';
System.out.println("\n======CHAR======");
System.out.println("nilai char c = " + c);
System.out.println("Nilai max = " + Character.MAX_VALUE);
System.out.println("Nilai min = " + Character.MIN_VALUE);
System.out.println("Besar char = " + Character.BYTES + " bytes");
System.out.println("Besar char = " + Character.SIZE + " bit");
// boolean hanya memiliki 2 nilai yaitu:
// boolean (nilai true atau false)
boolean val = false;
System.out.println("\n======BOOLEAN======");
System.out.println("nilai boolean val = " + val);
System.out.println("Nilai max = " + Boolean.TRUE);
System.out.println("Nilai min = " + Boolean.FALSE);
}
}