-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomArray.java
More file actions
35 lines (31 loc) · 1.02 KB
/
RandomArray.java
File metadata and controls
35 lines (31 loc) · 1.02 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
package RandomArray;
public class RandomArray {
static final int MAX_INDEX = 10;
public static void main(String[] args) {
int[][] a = new int[MAX_INDEX][MAX_INDEX];
//用于数组初始化
int value = 0;
int temp;
int row, column;
for(int i = 0; i < MAX_INDEX; i++)
for(int j = 0; j < MAX_INDEX; j++) {
a[i][j] = value;
value++;
}
for(int i = 0; i < MAX_INDEX; i++) {
for(int j = 0; j < MAX_INDEX; j++) {
row = (int)(Math.random() * MAX_INDEX);
column = (int)(Math.random() * MAX_INDEX);
temp = a[i][j];
a[i][j] = a[row][column];
a[row][column] = temp;
}
}
System.out.println("The content of array a is: ");
for(int i = 0; i < MAX_INDEX; i++) {
for(int j = 0; j < MAX_INDEX; j++)
System.out.printf("%4d",a[i][j]);
System.out.println();
}
}
}