Q:

Java program to find mean of a given number

belongs to collection: Java Basic Programs

0

Given N integer numbers and we have to find mean of all numbers using java program.

Example 1:

Input:
Entered numbers: 63, 25, 45
Output:
Mean of the given numbers is : 44

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program to find mean of given numbers in java

import java.util.Scanner;

public class CalculateMean
{
    public static void main(String args[])
    {
    	// initialize and declaring the objects.
        int n, i, sum=0, mean;
        int arr[] = new int[50];
        Scanner scan = new Scanner(System.in);
		
        // enter number you have to enter.
        System.out.print("How many Number you want to Enter : ");
        n = scan.nextInt();
		
        // enter the numbers.
        System.out.println("Enter " +n+ " Numbers : ");
      
        // this will access all numbers and make sum of the numbers.
        for(i=0; i<n; i++)
        {
            arr[i] = scan.nextInt();
            sum = sum + arr[i];
        }
        // fomula to calculate mean.
        mean = sum/n;
        System.out.print("Mean of the given numbers is : " +mean);
    }
}

Output

First run:
How many Number you want to Enter : 5
Enter 5 Numbers : 
25
36
95
52
58
Mean of the given numbers is : 53

Second run:
How many Number you want to Enter : 3
Enter 3 Numbers : 
63
25
45
Mean of the given numbers is : 44

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java Basic Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to build a calculator... >>
<< Java program to find sum of all digits ...