Java Program to find the Average of Three Numbers

Write a Java program to find the average of three numbers using the + and / arithmetic operator. First, it accepts three numbers of double type and then uses the arithmetic plus to add them and / operator to find the average.

package RemainingSimplePrograms;

import java.util.Scanner;

public class AvgOfThree1 {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Please Enter the first Number = ");
		double num1 = sc.nextDouble();
		
		System.out.print("Please Enter the Second Number = ");
		double num2 = sc.nextDouble();
		
		System.out.print("Please Enter the Third Number = ");
		double num3 = sc.nextDouble();
		
		double average = (num1 + num2 + num3)/ 3;
		System.out.println("\nThe Average of Three Numbers = " + average);
	}
}
Java Program to find the Average of Three Numbers

In this Java example, we created a calAvg function that finds and returns three numbers’ average.

package RemainingSimplePrograms;

import java.util.Scanner;

public class AvgOfThree2 {
	private static Scanner sc;
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		
		System.out.print("Please Enter the first = ");
		double num1 = sc.nextDouble();
		
		System.out.print("Please Enter the Second = ");
		double num2 = sc.nextDouble();
		
		System.out.print("Please Enter the Third = ");
		double num3 = sc.nextDouble();
		
		double average = calAvg(num1, num2, num3);
		System.out.println("\nThe Average = " + average);
	}
	
	public static double calAvg(double a, double b, double c) {
		return (a + b + c)/3;
	}
}
Please Enter the first = 99
Please Enter the Second = 124.7
Please Enter the Third = 33.89

The Average = 85.86333333333333