info@meritcampus.com    +91-85006-22255
...
`

Write code to find the minimum, maximum, count, total and average of the integer elements in the input array.

Input (Integer Array) Output
`{ 52, 34, 5, 78, 210, 76, 21 }` ``` Min = 5 Max = 210 Count (Number of Elements) = 7 Total = 52 + 34 + 5 + 78 + 210 + 76 + 21 = 476 Average = Total / Count = 476 / 7 = 68 ```
`{ 54, -36, 3, 74, -210, 176, 421, 0, 94 }` ``` Min = -210 Max = 421 Count (Number of Elements) = 9 Total = 54 + -36 + 3 + 74 + -210 + 176 + 421 + 0 + 94 = 576 Average = Total / Count = 576 / 9 = 64 ```

``` class CalculateStatistics {     public static void main(String s[])    {        int input[] = { 52, 34, 5, 78, 210, 76, 21 };        Statistics result = calculateStatistics(input);                System.out.println("Min = " + result.minimum);        System.out.println("Max = " + result.maximum);        System.out.println("Count = " + result.count);        System.out.println("Total = " + result.total);        System.out.println("Average = " + result.average);            }     public static Statistics calculateStatistics(int[] input)     { ```
```     } } class Statistics {     int minimum;     int maximum;     int count;     int total;     int average; } ```
Topic:

### User comments below.All of them might not be correct.

1.input the array
2.consider a[0] element
3.intialise for loop and take array
int min=a[0];
for(int i=0;i<n;i++)
{
if(min<a[i])
{
print min;
}
else
skip;
4.if(max>a[i])
{
print max;
}
else
{
skip
}
5.intialise int sum=0;
for(int i=0;i<n;i++)
{
sum=sum+a[i];
print sum;
}
else
{
skip
}

6.average=sum/n;
7.count=n-1;
8.print average,count;
9.here we can use recursion also
10.end;

Posted by Sai Veerendra    2014-12-09 06:56:18

here we have 5 Cases..
first create the Instance for the class Student..

case 1: Finding the min element..
take min variable and assign it to 0..
take an for loop to iterate through out the array..every time compare the a[i] with the a[min] if a[i] is less than a[min] than make min=i;

after iterating through out the for loop we have the index of the min values...so assign this value to student.min=array[min];

case 2: Finding the min element..
take max variable and assign it to 0..
take an for loop to iterate through out the array..every time compare the a[i] with the a[min] if a[i] is greater than a[max] than make max=i;

after iterating through out the for loop we have the index of the max value...so assign this value to student.max=array[max];

case 3:
number of elements is equal to the size of array
so student.count=input.length
case 4:
take an variable sum and must initilize it to 0..iterate thorugh the for loop add every element to the sum
sum+=array[i];
after coming out of the loop student.sum=sum;
case 5:
avg=sum/num of elements;
student.avg=student.sum/student.count;

Posted by Uday Kumar    2014-12-09 13:27:01

Sai Veerendra, you know how to solve it. "Do not include the code directly". These should be written in a such a way that, any person wanting to solve this should get an idea about how to solve but it should not give complete logic

Posted by Merit Campus    2014-12-10 05:09:42

This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Sai Veerendra,  for 'Second Correct Comment'. The 'lucky liker' is Asad Ahmed. Please login into Merit Campus using facebook, to claim your recharge. Go to http://java.meritcampus.com/earnings to raise the recharge.

Posted by Merit Campus    2014-12-10 07:51:16