Java Program to find the Average of Three Numbers

Write a Java program to find the average of three numbers using the / operator.

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 calve 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 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 = calAvg(num1, num2, num3);
		System.out.println("\nThe Average of Three Numbers = " + average);
	}
	
	public static double calAvg(double a, double b, double c) {
		return (a + b + c)/3;
	}
}
Please Enter the first Number = 99
Please Enter the Second Number = 124.7
Please Enter the Third Number = 33.89

The Average of Three Numbers = 85.86333333333333