150k views
4 votes
Write a complete Java program to: 1. prompt the user to enter all of his/her quiz scores. 2. calculate and display the average entered quiz score without the the lowest quiz score

1 Answer

3 votes

Answer:

Here is code in java.

import java.util.*;

import java.lang.*;

import java.io.*;

// main class

class Main

{

public static void main (String[] args) throws java.lang.Exception

{

try{

// declare variables

int n;

float m=Float.MAX_VALUE;

float sum=0,avg;

// Scanner class object to read input

Scanner sc=new Scanner(System.in);

System.out.println("Enter the Number of quiz:");

// read Number of quiz

n=sc.nextInt();

for(int i=1;i<=n;i++)

{

System.out.println("Enter the score of quiz "+i+":");

//read score of each quiz

float x=sc.nextFloat();

// calculate sum of all quiz

sum=sum+x;

//find the lowest quiz score

if(x<m)

m=x;

}

// subtract the lowest quiz score

sum=sum-m;

// find the Average

avg=sum/(n-1);

System.out.println("Average of "+(n-1)+" quiz without lowest quiz is: "+avg);

}catch(Exception ex){

return;}

}

}

Step-by-step explanation:

First read the Number of quiz and assign it to variable "n". Then read n Numbers of quiz score and calculate their sum.Find the minimum score and subtract it from the total sum of all quiz.then find the Average of n-1 Numbers and print the Output.

Output:

Enter the Number of quiz:

5

Enter the score of quiz 1:

1.2

Enter the score of quiz 2:

3.0

Enter the score of quiz 3:

5

Enter the score of quiz 4:

9

Enter the score of quiz 5:

4.5

Average of 4 quiz without lowest quiz is: 5.375

User Valyala
by
7.5k points