forked from serkanhelvacioglu/Java-IAU
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTextBox Array Example
More file actions
106 lines (65 loc) · 2.3 KB
/
TextBox Array Example
File metadata and controls
106 lines (65 loc) · 2.3 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package pack1;
import javax.swing.*;
import java.util.Random;
public class MultiArrayTextbox_Example {
public static void main(String[] args) {
int range;
int dimesion = 4;
range = Integer.parseInt(JOptionPane.showInputDialog(
null, "Enter RANGE Number", "Java", JOptionPane.QUESTION_MESSAGE));
Random rnd = new Random();
int[][] array1 = new int[4][4];
int[] arraytotal = new int[4];
int[] arraytotal1 = new int[2];
int[] arraytotal2 = new int[4];
int atotal = 0, btotal = 0, ctotal = 2;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
array1[i][j] = rnd.nextInt(range) + 1;
}
}
for (int i = 0; i < 4; i++) {
for (int a = 0; a < 4; a++) {
System.out.print(array1[i][a] + " ");
atotal += array1[i][a];
}
System.out.println("Total:" + atotal);
atotal = 0;
for (int f = 0; f < 2; f++) {
System.out.print(array1[i][f] + " ");
btotal += array1[i][f];
}
System.out.println("First two Column Total:" + btotal);
btotal = 0;
for (int z = 2; z < 4; z++) {
System.out.print(array1[i][z] + " ");
ctotal += array1[i][z];
}
System.out.println("Last two Column Total:" + ctotal);
ctotal = 0;
}
System.out.print("Rows Total :");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
arraytotal[i] += array1[j][i];
}
System.out.print(arraytotal[i] + " ");
}
System.out.println();
System.out.print("First Two Rows Total :");
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 4; j++) {
arraytotal1[i] += array1[j][i];
}
System.out.print(arraytotal1[i] + " ");
}
System.out.println();
System.out.print("Last Two Rows Total :");
for (int i = 2; i <4 ; i++) {
for (int j = 0; j < 4; j++) {
arraytotal2[i] += array1[j][i];
}
System.out.print(arraytotal2[i] + " ");
}
}
}