Ask Question

Write a program to read a list of nonnegative integers and to display the largest integer, the smallest integer, and the average of all the integers. The user indicates the end of the input by entering a negative sentinel value that is not used in finding the largest, smallest, and average values. The average should be a value of type double so that it is computed with a fractional part.

+1
Answers (1)
  1. Today, 18:50
    0
    The program to this question can be given as:

    Program:

    import java. util.*; / /import package.

    public class Main / /define class

    {

    public static void main (String[] ar) / /define main method

    {

    int grade=0, subject, i, sum=0, total = 0; / /define variables

    System. out. print ("Enter the number of subject:"); / /message

    Scanner ob = new Scanner (System. in); / /creating Scanner class object.

    subject = ob. nextInt (); / /taking input from user.

    System. out. println ("Enter grades in number:");

    for (i=1; i<=subject; i++) / /loop.

    {

    grade = ob. nextInt (); / /input grades.

    sum=sum+grade; / /add grades.

    }

    //System. out. println ("sum:"+sum);

    total = (sum*100) / (subject*100); / /persentage

    //System. out. println ("persentage:"+total);

    //conditional statement

    System. out. print ("your grade : ");

    if (total>=90) / /check persentage

    {

    System. out. print ("A grade"); / /print message

    }

    else if (total>=80)

    {

    System. out. print ("B grade");

    }

    else if (total >=70)

    {

    System. out. print ("C grade");

    }

    else if (total >=60)

    {

    System. out. print ("D grade");

    }

    else

    {

    System. out. print ("E grade");

    }

    }

    }

    Output:

    Enter the number of subject: 3

    Enter grades in number:

    79

    76

    59

    your grade : C grade

    Explanation:

    In the above program firstly we import the package for user input then we declare the class name main in this class we declare the main method in the main main method we declare the variable. Then we create a scanner class object for user input the we take input from the user and add all number and put the value into the sum variable and the we calculate the percentage and put into the total variable then we the conditional statement in this part we check the value between the different parameters if the value match then we print the grade.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program to read a list of nonnegative integers and to display the largest integer, the smallest integer, and the average of all the ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers