Answer:
import java.util.Scanner;
import java.util.*;
import java.util.Collections;
class Main
{
public static void main(String[] args)
{
List<Integer> Scores = new ArrayList<Integer>();
Scanner sc1=new Scanner(System.in);
int i =0;
int a=0;
do
{
System.out.println("Enter score");
a =sc1.nextInt();
if (a <= 0)
{
System.out.println("You entered wrong score");
continue;
}
else if ( a < 10 && a >0)
{
System.out.println("You entered wrong score");
continue;
}
else
{
Scores.add(a);
}
i++;
}while(a!=99);
int max= Collections.max(Scores);
int min=Collections.min(Scores);
int sum=0;
float averg =0;
for(i=0; i<=Scores.size()-1;i++)
{
sum += Scores.get(i);
}
averg= sum/Scores.size();
System.out.println("Maximum score" +max);
System.out.println("Minimum score"+min);
System.out.println("Average:"+averg);
}
}
Explanation:
Remember we need to use Arraylist and not array, as we do not know how many scores we are going to have. And we use Collections for this, where we have functions for finding maximum and minimum for arraylist, however, for average, we need to calculate. However, one should know that Arraylist has better options available as compare to arrays.