In: Computer Science
Write a program in Java to:
code:
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("How many scores you want to enter : ");
int size = sc.nextInt();
int[] scores = new int[size];
System.out.println("Enter your scores");
for(int i=0;i<size;i++){
scores[i] = sc.nextInt();
}
//finding greatest score and average score
int max = -99;
double sum = 0;
for(int i=0;i<size;i++){
if(scores[i] > max){
max = scores[i];
}
sum+=scores[i];
}
System.out.printf("\nGreatest Score : %d",max);
double avg = sum/size;
System.out.printf("\nAverage Score : %.2f",avg);
char grade;
//finding grade
if(avg >= 90){
grade = 'A';
}else if(avg >= 80){
grade = 'B';
}else if(avg >= 70){
grade = 'C';
}else if(avg >= 60){
grade = 'D';
}else{
grade = 'F';
}
System.out.printf("\nYour Grade : %c",grade);
System.out.printf("\nEntered Scores : ");
for(int i=0;i<size;i++)
System.out.printf("\n%d",scores[i]);
}
}