Using a loop, write a program that takes 10 values representing exam grades (bet
ID: 3839848 • Letter: U
Question
Using a loop, write a program that takes 10 values representing exam grades (between 0 and 100) from the keyboard and outputs the mini mum value, maximum value, and average value of all the values entered. Your program should not accept values less than 0 or greater than 100.
Can someone please fix my code for me? The error is highlighted. Please fix any part of my code that may be wrong.
import java util. Scanner; 2 public class Ch6PA1 public static void main (Stringl] args) t TODO Auto-generated method stub int[] grades new int[10] Scanner keyboard new Scanner (System.in); for (int i 0; iExplanation / Answer
Use object of Scanner class ie keyboard to invoke class method nextInt()
import java.util.*;
class Ch6PA1
{
public static void main (String[] args)
{
int[] grades = new int[10];
Scanner keyboard = new Scanner(System.in);
for(int i=0;i<10;i++)
{
System.out.println("Enter grade "+(i+1)+" : ");
int input = keyboard.nextInt();
if(input < 0 || input>100)
{
System.out.println("Invalid input entered");
i--;
}
else
grades[i] = input;
}
int min = grades[0];
int max = grades[0];
double sum = grades[0];
for(int i=0;i<10;i++)
{
if(grades[i] < min) min = grades[i];
if(grades[i] > max) max = grades[i];
sum = sum + grades[i];
}
System.out.println("Minimum Grade given by "+ min);
System.out.println("Maximum grade given by "+max);
System.out.println("Average grade given by "+sum/10);
}
}
Output:
Enter Grade 1 : 45
Enter Grade 2 : 67
Enter Grade 3 : 34
Enter Grade 4 : 55
Enter Grade 5 : -2
invalid input entered
Enter Grade 5 : 77
Enter Grade 6 : 109
Invalid input entered
Enter Grade 6 : 65
Enter Grade 7 : 74
Enter Grade 8 : 61
Enter Grade 9 : 69
Enter Grade 10 : 57
Minimum Grade given by 34
Maximum grade given by 77
Average grade given by 64.9
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.