Average Of Three Numbers In Java - Math Traders

Latest

Average Of Three Numbers In Java

Program to find Average Of Three Numbers In Java


In this java exercise question we will learn how to compute or how to calculate average of three numbers in java.
We will write a very simple code in java to calculate the average of three numbers in java. As we know that average of numbers is nothing but the ratio of sum of terms to the number of terms.

Let's understand through a very simple java program that how you calculate average of numbers.

package ex1;
import java.util.*;

public class avg1 {

public static void main(String[] args) {
float a,b,c,avg;
System.out.println("enter 3 numbers");
Scanner kb = new Scanner(System.in);
a = kb.nextFloat();
b = kb.nextFloat();
c = kb.nextFloat();
avg = (a+b+c)/3;
System.out.println("average of numbers is :" +avg);

}

}

Input: enter 3 numbers
                    8    9 And  4

Output: 7.0

No comments:

Post a Comment