-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiteral.java
More file actions
32 lines (24 loc) Β· 820 Bytes
/
Literal.java
File metadata and controls
32 lines (24 loc) Β· 820 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
package practice;
public class Literal {
public static void main(String[] args) {
byte b1 = 10; // decimal
byte b2 = 0b1010; // binary
byte b3 = 012; // octal
byte b4 = 0XA; // hexadecimal
System.out.println(b1); // 10
System.out.println(b2); // 10
System.out.println(b3); // 10
System.out.println(b4); // 10
// long val = 999999999999; // The literal 999999999999 of type int is out of range
long val = 999999999999L;
System.out.println(val); // 999999999999
// for readability purpose we can use underscore to seperate large numbers
long value = 999_999_999_999L;
System.out.println(value); // 999999999999
// float f = 12.42; // Type mismatch: cannot convert from double to float
float f = 12.42f;
double d = 12.53d;
System.out.println(f);
System.out.println(d);
}
}