import java.util.stream.IntStream;
public class Question {
public static void main(String[] args) {
String[] name = { "Johnson", "Aniston", "Cooper", "Gupta", "Blair", "Clark", "Kennedy", "Bronson", "Sunny",
"Smith" };
int[][] scores = { { 85, 83, 77, 91, 76 }, { 80, 90, 95, 93, 48 }, { 78, 81, 11, 90, 73 },
{ 92, 83, 30, 69, 87 }, { 23, 45, 96, 38, 59 }, { 60, 85, 45, 39, 67 }, { 77, 31, 52, 74, 83 },
{ 93, 94, 89, 77, 97 }, { 79, 85, 28, 93, 82 }, { 85, 72, 49, 75, 63 } };
printResults(name, scores);
calculateEachAverrage(name, scores);
findBestStudent(name, scores);
}
public static void printResults(String[] name, int[][] scores) {
for (int i = 0; i < name.length; i++) {
System.out.print(name[i]);
for (int j = 0; j < scores.length; j++) {
for (int j2 = 0; j2 < scores[j].length; j2++) {
System.out.printf("%4d", scores[j][j2]);
}
System.out.println();
}
}
}
public static void calculateEachAverrage(String[] names, int scores[][]) {
for (int i = 0; i < scores.length; i++) {
for (int g = 0; g < scores[i].length; g++) {
System.out.print(scores[i][g] + " ");
}
int avg = (int) IntStream.of(scores[i]).average().getAsDouble();
System.out.println("The avarage is: " + avg);
System.out.println();
}
}
public static void findBestStudent(String[] names, int scores[][]) {
int averages[] = new int[10];
int avg = 0;
for (int i = 0; i < scores.length; i++) {
for (int g = 0; g < scores[i].length; g++) {
}
avg = (int) IntStream.of(scores[i]).average().getAsDouble();
for (int j = 0; j < averages.length; j++) {
averages[j] = avg;
}
}
int maxValue = 0;
int indexMaxValue = 0;
for (int i = 0; i < averages.length; i++) {
if (maxValue < averages[i]) {
maxValue = averages[i];
indexMaxValue = i;
}
}
for (int i = 0; i < names.length; i++) {
if (i == indexMaxValue) {
System.out.println(names[i] + " has value: " + maxValue);
}
}
}
}
Comments
Leave a comment