In this tutorial, we will see simple java program to calculate arithmetic mean.
Here is simple algorithm to calculate arithmetic mean.
- Calculate sum of elements in the array
- Divide it by total number of element in the array.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
import java.util.Scanner; public class ArithMeanCalc { public static void main(String args[]) { int cnt, i, sum=0, mean; int numArr[] = new int[50]; Scanner scan = new Scanner(System.in); System.out.print("Please enter count of numbers you want to Enter ? "); cnt = scan.nextInt(); System.out.print("Enter " +cnt+ " Numbers : "); for(i=0; i<cnt; i++){ numArr[i] = scan.nextInt(); sum = sum + numArr[i]; } mean = sum/cnt; System.out.print("Arithmetic Mean = " +mean); } } |
Output:
Please enter count of numbers you want to Enter ? 5
Enter 5 Numbers : 67 54 65 38 96
Arithmetic Mean = 64
Enter 5 Numbers : 67 54 65 38 96
Arithmetic Mean = 64
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.