Repository navigation
Expand file tree
/
Copy pathunit1_1_4.java
More file actions
executable file
·50 lines (35 loc) · 1.55 KB
/
Copy pathunit1_1_4.java
File metadata and controls
executable file
·50 lines (35 loc) · 1.55 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
class unit1_1_4 {
public static void main(String[] args) {
// Implicit Conversion
double x = 10; // double variable is assigned with integer value.
System.out.println("double x: " + x);
float y = 10; // float variable is assigned with integer value.
System.out.println("float y: " + y);
Integer z = 100; // or Integer z = new Integer(100);
System.out.println("Integer z: " + z); // implicitly calls toString()
System.out.println("Integer z.toString(): " + z.toString());
System.out.println("Integer z+10: " + (z+10));
// args is an array which is a reference type
System.out.println("args: " + args);
// Primitive data type name
double VAR = 3.14;
System.out.println("double VAR: " + VAR);
// String + int
System.out.println("Harry" + 731);
// int + String
System.out.println(731 + 10);
System.out.println(731 + 10 + "Harry");
System.out.println(731 + "Harry" + 10 + 15 + "Potter");
// final
final double PI = 22.0 / 7 ;
System.out.println("double PI: " + PI);
// change the value of PI. End up with compilation error.
// PI = 100;
// 0000 0000 0000 0000 0000 0000 0000 0000
// 0000 0000 0000 0000 0000 0000 0000 0001
// 0000 0000 0000 0000 0000 0000 0000 0010
// 1111 1111 1111 1111 1111 1111 1111 1110
// 1111 1111 1111 1111 1111 1111 1111 1111
// 1 0000 0000 0000 0000 0000 0000 0000 0000
}
}