Respuesta :
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.
The program is an illustration of loops and conditional statements.
Loops are used to execute repetitive operations, while conditional statements are executed based on the truth value of its condition.
The program in Java where comments are used to explain each line is as follows:
import java.util.*;
class Main{
public static void main(String[] args) {
//This creates a Scanner Object
Scanner input=new Scanner(System.in);
//This declares and initializes all integer variables
int num, count =0, sum = 0, max = Integer.MIN_VALUE; int min = Integer.MAX_VALUE;
//This declares and initializes the average variable
float avg =0;
//The following is repeated until the user enters 99
do{
//Prompts the user for a score
System.out.print("Score: ");
//Get input for score
num =input.nextInt();
//Inputs less than 0 or greater than 10 are invalid
if (num < 0 || num >10){
System.out.println("Invalid input");
}
//For valid inputs
else{
//This keeps count of valid inputs
count++;
//This adds valid inputs
sum+=num;
//This gets the maximum of valid inputs
if(num > max){
max = num;
}
//This gets the minimum of valid inputs
if(num < min){
min = num;
}
}
}
while(num != 99);
//Calculate average
avg= sum/count;
//Print the highest score
System.out.println("Highest: " +max);
//Print the least score
System.out.println("Lowest: "+min);
//Print the average score
System.out.println("Average: "+avg);
}
}
Read more about similar programs at:
https://brainly.com/question/17763987
