-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcount1.java
More file actions
44 lines (41 loc) · 1.17 KB
/
Copy pathcount1.java
File metadata and controls
44 lines (41 loc) · 1.17 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
package matrix;
import java.util.Scanner;
public class count1 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int r, c,count=0;
System.out.println("enter number of rows : ");
r = s.nextInt();
System.out.println("enter number of columns : ");
c = s.nextInt();
int ar[][] = new int[r][c];
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
System.out.println("enter the element : "+(i+1)+" "+(j+1));
ar[i][j] = s.nextInt();
}
}
int countar[]=new int[r];
for (int i = 0; i < r; i++) {
count=0;
for (int j = 0; j < c; j++) {
if(ar[i][j]==1)
{
count++;
}
}
countar[i]=count;
}
int h=countar[0];
int index=0;
for(int i=1;i<countar.length;i++)
{
if(countar[i]>h)
{
h=countar[i];
index=i;
}
}
System.out.println(index);
}
}