forked from serkanhelvacioglu/Java-IAU
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMultiArrayExample
More file actions
70 lines (41 loc) · 1.07 KB
/
MultiArrayExample
File metadata and controls
70 lines (41 loc) · 1.07 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
package PACK1;
import java.util.Random;
import javax.swing.JOptionPane;
import sun.reflect.generics.tree.BaseType;
public class Muli_Arrays {
public static void main(String[] args) {
Random rnd = new Random();
int [][] base_array = new int [4][4];
int [][] sum_array = new int [4][4];
String output="";
for(int i=0; i<4; i++){
for (int j=0; j<4; j++){
base_array[i][j]=rnd.nextInt(9)+1;
output+=base_array[i][j]+" ";
}
output+="\n";
}
for(int i=0; i<4; i++){
for(int j=0; j<4; j++){
if(j==0){
sum_array[i][j]=base_array[i][j]+base_array[i][j+1];
}
else if(j==3){
sum_array[i][j]=base_array[i][j]+base_array[i][j-1];
}
else {
sum_array[i][j]=base_array[i][j-1]+base_array[i][j+1];
}
}
}
output+="\nSum Array\n";
for(int i=0; i<4; i++){
for (int j=0; j<4; j++){
output+=sum_array[i][j]+" ";
}
output+="\n";
}
JOptionPane.showMessageDialog(null, "Base Array\n"+output,"JAVA",
JOptionPane.INFORMATION_MESSAGE);
}
}