- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java program to calculate mean of given numbers
Mean is an average value of given set of numbers. It is calculated similarly to that of the average value. Adding all given number together and then dividing them by the total number of values produces mean.
For Example
Mean of 3, 5, 2, 7, 3 is (3 + 5 + 2 + 7 + 3) / 5 = 4
Algorithm
- Take an integer set A of n values.
- Add all values of A together.
- Divide result of Step 2 by n.
- The result is mean of A's values.
Program
public class CaculatingMean { public static void main(String args[]){ float mean; int sum, i; int n = 5; int a[] = {2,6,7,4,9}; sum = 0; for(i = 0; i < n; i++) { sum+=a[i]; } System.out.println("Mean ::"+ sum/(float)n); } }
Output
Mean::5.6
Advertisements