Calculate And Print The Average Of Five Numbers | Java Programs

Output:

*** Average Of Five Numbers ***
Input first number:  1
Input second number: 9
Input third number:  4
Input fourth number: 5
Enter fifth number:  3
Average of five numbers is: 4.4

Click Here For Java Online Compiler

Solution:

import java.util.Scanner;

public class AverageOfNumbers {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("*** Average Of Five Numbers ***" + "\n");

        System.out.print("Input first number:  ");
        double num1 = in.nextInt();

        System.out.print("Input second number: ");
        double num2 = in.nextInt();

        System.out.print("Input third number:  ");
        double num3 = in.nextInt();

        System.out.print("Input fourth number: ");
        double num4 = in.nextInt();

        System.out.print("Enter fifth number:  ");
        double num5 = in.nextInt();

        double sum = num1 + num2 + num3 + num4 + num5;
        System.out.print("Average of five numbers is: " + sum / 5);
    }
}
Share This :

Related Post

avatar

nice article in your blog.thank you for sharing useful info.
visit
web programming tutorial
welookups

delete 29 August 2018 at 20:26



sentiment_satisfied Emoticon