Ask Question
24 January, 09:33

Write a program that asks the user to input four numbers (one at a time). After the four numbers have been supplied, it should then calculate the average of the four numbers. The average should then be displayed.

+2
Answers (1)
  1. 24 January, 11:12
    0
    Output

    Enter first number:

    1

    Enter second number:

    2

    Enter third number:

    3

    Enter fourth number:

    4

    Average: 2.5

    Explanation:

    Below is the java program to calculate the average of four numbers:-

    import java. util. Scanner;

    public class Average {

    public static void main (String[] args) {

    int a, b, c, d;

    double average=0.0;

    Scanner s=new Scanner (System. in);

    System. out. println ("Enter first number: ");

    a=s. nextInt ();

    System. out. println ("Enter second number: ");

    b=s. nextInt ();

    System. out. println ("Enter third number: ");

    c=s. nextInt ();

    System. out. println ("Enter fourth number: ");

    d=s. nextInt ();

    average = (a+b+c+d) / 4.0;

    System. out. println ("Average: "+average);

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that asks the user to input four numbers (one at a time). After the four numbers have been supplied, it should then ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers