Arrays | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

4th Jun 2018, 6:09 AM
Fiodora Taslim
Fiodora Taslim - avatar
1 Answer
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; }
4th Jun 2018, 10:37 AM
Krzysztof303
Krzysztof303 - avatar