- Notifications
You must be signed in to change notification settings - Fork 366
/
Copy pathLargestRowSum.java
44 lines (38 loc) · 1.26 KB
/
LargestRowSum.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
//Find largest row sum
packageTwo_Dimensional_Array;
importjava.util.Scanner;
publicclassLargestRowSum {
publicstaticintlargestcolsum(int [] [] arr2) {
intmax = Integer.MIN_VALUE;
for (inti = 0; i < arr2.length; i++) {
intsum = 0;
for (intj = 0; j < arr2[i].length; j++) {
sum = sum + arr2[i][j];
}
if( sum > max) {
max = sum;
}
}
returnmax;
}
publicstaticint [] [] takingInput() {
Scannersc = newScanner(System.in);
System.out.println("Enter the number of rows: ");
introws = sc.nextInt();
System.out.println("Enter the number of columns: ");
intcols = sc.nextInt();
int [] [] arr = newint[rows][cols];
for (inti = 0; i < rows; i++) {
for (intj = 0; j < cols; j++) {
System.out.println("Enter the element at " + i + " rows " + j + " columns: ");
arr[i][j] = sc.nextInt();
}
}
returnarr;
}
publicstaticvoidmain(String[] args) {
int [] [] arr2 = takingInput();
intn = largestcolsum(arr2);
System.out.println(n);
}
}