You can also find the mean of many numbers without asking total number of items using array. Here we have to declare an array with a limit like 10. Like int nums = new int; here this program accept only 10 number to find mean.
After accepting all numbers, then program will find the mean using following mathematical formula.
Mean = Sum of total numbers of elements / number of elements.
Example: If number are 1,2,3.
Here sum is = 1+2+3 = 6
Here number of elements are 3
So that Mean is = 6 / 3 = 2
Here class name is ‘mean’, so you should save your file with name ‘mean.java’.
[Lean here how to create, compile and run a java application program here.]
double sum = 0;
void findmean() throws IOException
BufferedReader Br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("\n Mean of how many numbers : ");
num = Integer.parseInt(Br.readLine());
int nums = new int[num+1];
for(int i = 1;i<=num;i++)
System.out.print("\n Enter " + i + " number : ");
sum = sum + nums[i];
result = sum / num;
System.out.print("\n Mean of above numbers is : " + result );
public static void main(String s) throws IOException
mean mn = new mean();
Mean of how many numbers: 5
Enter 1 st Number : 1
Enter 2 nd Number : 2
Enter 3 rd Number : 3
Enter 4 th Number : 4
Enter 5 th Number : 5
Mean of above number is : 3.0