-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTypes.java
More file actions
43 lines (33 loc) · 1.12 KB
/
Copy pathDataTypes.java
File metadata and controls
43 lines (33 loc) · 1.12 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
public class DataTypes {
public static void main(String[] args) {
/* byte - 1 [-128 to 127]
* short - 2
* int - 4
* long - 8
* float - 4
* double - 8
* char - 2
* boolean - 1 */
//byte is used for small numbers
byte ages = 12; // 1 byte
System.out.println("Age: " + ages);
//char is used for single characters
char letter = '@';
System.out.println("Letter: " + letter);
//boolean is used for true/false values
boolean isAdult = true;
System.out.println("Is Adult: " + isAdult);
//float is used for decimal numbers
float pi = 3.14F;
System.out.println("Pi: " + pi);
//int is used for larger numbers
int phone = 1234567890;
System.out.println("Phone: " + phone);
//long is used for larger numbers
long phone2 = 1234567890000L;
System.out.println("Phone2: " + phone2);
//double is used for larger decimal numbers
short n = 240;
System.err.println("Short: " + n);
}
}