-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathHello.java
More file actions
88 lines (69 loc) · 1.7 KB
/
Copy pathHello.java
File metadata and controls
88 lines (69 loc) · 1.7 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
import java.lang.reflect.Array;
import java.util.Arrays;
public class Hello {
public static void main(String[] args) {
System.out.println("Hello, world!");
c1();
c2();
// ------------------------------------------
Outer outer = new Outer("Nested"); // 实例化一个Outer
Outer.Inner inner = outer.new Inner(); // 实例化一个Inner
inner.hello();
}
private static void c1() {
char c1 = 'A';
char c2 = '中';
int age = 25;
String s = "aeg is " + age;
System.out.println(s);
// ---------------------------------------------
String x = "hello";
String t = x;
x = "world";
System.out.println(t);
}
private static void c2() {
int[] ns = new int[3];
ns[0] = 1;
ns[1] = 2;
ns[2] = 3;
System.out.println(ns);
System.out.println(Arrays.toString(ns));
System.out.println(ns.length);
int[][] magicSquare =
{
{16, 3, 2, 13},
{5, 10, 11, 8},
{9, 6, 7, 3}
};
System.out.println(Arrays.toString(magicSquare));
for (int[] a:magicSquare) {
System.out.println(Arrays.toString(a));
}
// -------------------------------------------
String[] names = {"ABC", "XYZ", "zoo"};
String s = names[1];
names[1] = "cat";
System.out.println(s);
}
}
class Outer {
private String name;
Outer(String name) {
this.name = name;
}
class Inner {
void hello() {
System.out.println("Hello, " + Outer.this.name);
}
}
void asyncHello() {
Runnable r = new Runnable() { // todo: 匿名类
@Override
public void run() {
System.out.println("Hello, " + Outer.this.name);
}
};
new Thread(r).start();
}
}