Ask Question
11 November, 00:04

Write a program that reads three whole numbers and displays the average of the three number. Sample Run #: java Average3 Interactive Session.

1. Enter the first integer: 8

2. Enter the second integer: 10

3. Enter the third integer: 18

The average of 8, 10, and 18 = 12.0.

+5
Answers (1)
  1. 11 November, 03:57
    0
    The program to this question as follows:

    Program:

    import java. util.*; / /import package

    class Average / /defining class Average

    {

    public static void main (String[] args) / /defining main method

    {

    int a1, b2, c3; //defining integer variable

    float avg; / /defining float variable

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

    System. out. print ("input first number: "); / /print message

    a1=obz. nextInt (); / /input value by user

    System. out. print ("input second number: "); / /print message

    b2=obz. nextInt (); / /input value by user

    System. out. print ("input third number: "); / /print message

    c3=obz. nextInt (); / /input value by user

    avg=a1+b2+c3/3; / /calculating average

    System. out. print ("The average of "+a1+","+b2+", and " + c3+"=" + avg); //print value

    }

    }

    Output:

    input first number: 8

    input second number: 10

    input third number: 18

    The average of 8,10, and 18=24.0

    Explanation:

    In the above code, a class "Average" is defined inside this class the main function is declared in this method three integer variable "a1, b2, and a3" is declared, which input the value from the user side. in this method, a float variable avg is defined that calculates its average value.

    In the next step, a scanner class object is created, that uses the above integer variable values. In the "avg" variable add all integer variables then divide its value by 3. At the print, method is used that prints avg variable value.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a program that reads three whole numbers and displays the average of the three number. Sample Run #: java Average3 Interactive ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers