Here is a program in Java that prompts the user to enter the number of students
ID: 3630342 • Letter: H
Question
Here is a program in Java that prompts the user to enter the number of students and each students score, check input validation, and display the highest score. I need to take the program below, and add to calculate the lowest grade and average grade of double type also.Here is program:
import java.util.*;
class StudentHighestScore
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Please input the total number of students: ");
int no = sc.nextInt();
int max = 0;
for(int i=0; i<no; i++)
{
System.out.println("Please input the students' grade:");
int k = sc.nextInt();
if(k >max) max = k;
}
System.out.println("The highest grade is: " + max);
}
}
Explanation / Answer
please rate - thanks
import java.util.*;
class StudentHighestScore
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Please input the total number of students: ");
int no = sc.nextInt();
int max = 0,min=10000,sum=0;
double average;
for(int i=0; i<no; i++)
{
System.out.println("Please input the students' grade:");
int k = sc.nextInt();
sum+=k;
if(k >max) max = k;
if(k<min)
min=k;
}
average=sum/(double)no;
System.out.println("The highest grade is: " + max);
System.out.println("The lowest grade is: " + min);
System.out.println("The average grade is: " + average);
}
}