Java Program to find out the average of three integer numbers

Here we are explaining how to write a java program to find out the average of three numbers. So first we have to read three integer numbers from the user and then we will find out the average of that number as sum/3.

How to implement the java program to find out the average of three integer numbers?

First, we have to declare the class AverageNumber.Then we have to declare the variables a,b,c, to hold the three integer numbers. Then read the numbers from the user using the scanner class object. Then find out the sum of the integer numbers as sum=a+b+c. Then calculate the average as avg=sum/3.Then display average as avg using system.out.println().


STEP 1: Declare the class AverageNumber with a public modifier.

STEP 2: Open the main() to start the program, Java program execution starts with the main()

STEP 3: Declare the integer variables a,b,c,sum.

STEP 4: Create the object of the scanner class as sc.

STEP 5: Read the three numbers into the variables a,b,c.

STEP 6: Findout sum as sum=a+b+c.

STEP 7: Calculate average as avg=sum/3.

STEP 8: Display average as avg.

Java Source Code

                                          import java.util.Scanner;
public class AverageNumber 
    public static void main(String[] args) 
        int a,b,c,sum;
        Scanner sc = new Scanner(;
        System.out.println("Enter the first number:");
        a = sc.nextInt();
        System.out.println("Enter the second number:");
        b = sc.nextInt();
        System.out.println("Enter the third number:");
        c = sc.nextInt();
      double avg=sum/3;
      System.out.println("Sum of the numbers is "+avg);


Enter the first number:10
Enter the second number:10
Enter the third number:10
Average of the numbers is 10.0