-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathJOptionPane.java
More file actions
72 lines (45 loc) · 1.23 KB
/
JOptionPane.java
File metadata and controls
72 lines (45 loc) · 1.23 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
package pack1;
import java.util.Random;
import javax.swing.JOptionPane;
public class Array2 {
public static void main(String[] args) {
int range;
int dimension;
range=Integer.parseInt(JOptionPane.showInputDialog(
null,
"Enter the range of random numbers",
"JAVA",
JOptionPane.QUESTION_MESSAGE));
dimension=Integer.parseInt(JOptionPane.showInputDialog(
null,
"Enter dimension number",
"JAVA",
JOptionPane.QUESTION_MESSAGE));
Random rnd = new Random();
int total=0;
int [] array_total = new int [dimension];
int [][] array1 = new int [dimension][dimension];
for(int i=0; i<dimension; i++){
for(int j=0; j<dimension; j++){
array1[i][j]= rnd.nextInt(range)+1;
}
}
String output="";
for(int i = 0; i<dimension; i++){
output+=(i+1)+".Line ";
for(int j=0; j<dimension; j++){
output+=array1[i][j]+" ";
array_total[i]+=array1[j][i];
total+=array1[i][j];
}
output+="Total: "+total+"\n";
total=0;
}
output+="Total: ";
for(int i=0; i<dimension; i++){
output+=array_total[i]+" ";
}
output+="\n";
JOptionPane.showMessageDialog(null, output,"Output",JOptionPane.INFORMATION_MESSAGE);
}
}