0
Arrays
Write a program to process the students scores. 1) Ask the user to input number of students 2) create an array with elements of input number 3) input the students score one by one 4) find out the average score 5) find out the highest score and its index number 6) find out the lowest score and its index number
1 Resposta
0
use Scanner and nextInt() to get the numbers put them to ArrayList by arrayList.add(nextInt()), then find max by
Integer max = Collections.max(arrayList);
find min by
Integer min = Collections.min(arrayList);
To find them index in ArrayList do like that:
int maxIndex = arrayList.indexOf(max);
int minIndex = arrayList.indexOf(min);
To get average value from this build method like that:
public double calculateAverage(List <Integer> marks) {
Integer sum = 0; if(!marks.isEmpty()) {
for (Integer mark : marks) { sum += mark; } return sum.doubleValue() / marks.size();
} return sum;
}