-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudentReport.java
More file actions
45 lines (37 loc) · 1.18 KB
/
Copy pathStudentReport.java
File metadata and controls
45 lines (37 loc) · 1.18 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
import java.util.Arrays;
public class StudentReport {
public int[] SortStudentMarks(int input1, int input2, int[][] input3) {
int[] res = new int[input1];
int[] avg = new int[input2];
for (int j = 0; j < input2; j++) {
int sum = 0;
for (int i = 0; i < input1; i++) {
sum += input3[i][j];
}
avg[j] = sum / input2;
}
// Minimum index
int index = -1;
int value = Integer.MAX_VALUE;
for (int i = 0; i < input2; i++) {
if (avg[i] < value) {
value = avg[i];
index = i;
}
}
for (int i = 0; i < input1; i++) {
int sum = 0;
for (int j = 0; j < input2; j++) {
if (j != index) {
sum += input3[i][j];
}
}
res[i] = sum;
}
return res;
}
public static void main(String[] args) {
StudentReport obj = new StudentReport();
System.out.println(Arrays.toString(obj.SortStudentMarks(3, 5, new int[][]{{75, 76, 65, 87, 87}, {78, 76, 68, 56, 89}, {67, 87, 78, 77, 65}})));
}
}