logo image

Java program to print average of given 3 numbers



Following program shows you how to print average of given 3 numbers. In this program we get inputs from user and calculate average of given 3 numbers using following formula Average of given 3 numbers = (input1 + input2 + input3) / 3

import java.util.Scanner;

public class BasicMath12 {

	public static void main(String[] args) {

		int input1;
		int input2;
		int input3;

		Scanner in = new Scanner(System.in);

		System.out.println("Enter first number:");
		input1 = in.nextInt();

		System.out.println("Enter second number:");
		input2 = in.nextInt();

		System.out.println("Enter third number:");
		input3 = in.nextInt();

		int result = (input1 + input2 + input3) / 3;

		System.out.println("The average of three numbers: " + result);

	}
}

Output:

Enter first number:
20
Enter second number:
10
Enter third number:
30
The average of three numbers: 20