-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHAQ5.java
49 lines (47 loc) · 954 Bytes
/
HAQ5.java
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
package java_primer;
public class HAQ5 {
public static void main(String[]args) {
int a[][]= new int[4][4];
for (int i=0; i<4; i++){
for (int j=0; j<4; j++){
a[i][j]=(int)(2*Math.random());
}
}
for (int i=0; i<4; i++){
for (int j=0; j<4; j++){
System.out.print(a[i][j]+" ");
}
System.out.println();
}
System.out.println("The largest row index: ");
int maxrowIndex=0, maxrow=0;
for (int i=0;i<4 ;i++){
int count=0;
for (int j=0; j<4; j++){
if (a[i][j]==1){
count++;
}
if (count>maxrow){
maxrow=count;
maxrowIndex=i;
}
}
}
System.out.println(maxrowIndex);
System.out.println("The largest column index: ");
int maxcolIndex=0, maxcol=0;
for (int i=0;i<4 ;i++){
int count2=0;
for (int j=0; j<4; j++){
if (a[i][j]==1){
count2++;
}
if (count2>maxcol){
maxcol=count2;
maxcolIndex=i;
}
}
}
System.out.println(maxcolIndex);
}
}