ADVERTISEMENT
ADVERTISEMENT

Java program to find mean of a given number

In this java program, we are going to learn how to read N numbers and find the mean of all input number?
Submitted by IncludeHelp, on November 15, 2017

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

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

Java Basic Programs »


ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.