Software & Finance Forums

### Author Topic: Java - Sum, Average, Min and Max for N numbers  (Read 1753 times)

#### kathir

• Sr. Member
• Posts: 283
##### Java - Sum, Average, Min and Max for N numbers
« on: December 02, 2011, 02:09:47 pm »
Could you please help me out in C# that accepts N numbers as input and compute the following values:

1) Sum
2) Average
3) Minimum
4) Maximum

Code: (Java)
```//Source Code Listing

import java.lang.*;
import java.util.*;
import java.io.*;

class MinMaxAvgSum
{
{
try
{
}
catch (Exception e)
{

e.printStackTrace();
return "";
}
}

{
try
{
}
catch (Exception e)
{

e.printStackTrace();
return 0;
}
}

public static void main(String[] args)
{
System.out.println("Enter the total numbers:");
int[] arrNumbers = new int[n];

for (int i = 0; i < n; i++)
{
System.out.format("Enter %d No.: ", i + 1);
}

int min = arrNumbers[0];
int max = arrNumbers[0];
int sum = 0;
double average = 0;
for (int i = 0; i < n; i++)
{
sum += arrNumbers[i];
if (min > arrNumbers[i])
min = arrNumbers[i];
if (max < arrNumbers[i])
max = arrNumbers[i];
}
average = (double)sum / n;

System.out.format("\nSum\t: %d", sum);
System.out.format("\nAverage\t: %.2f", average);
System.out.format("\nMin\t: %d", min);
System.out.format("\nMax\t: %d", max);
}
}

/***
The output is given below:
Enter the total numbers:5
Enter 1 No.: 100
Enter 2 No.: 200
Enter 3 No.: 101
Enter 4 No.: 201
Enter 5 No.: 501

Sum     : 1103
Average : 220.60
Min     : 100
Max     : 501
Press any key to continue . . .

***/
```

#### Harriettlof

• Group8
• Posts: 6
##### Java Sum Average Min and Max for N numbers
« Reply #1 on: January 20, 2017, 08:14:32 am »
I am sending a webrequest to page and i want to read the source code of the response , how can i do that ?

Disclaimer: This web site is for educational and informational purposes only. Click here to read the Disclaimer.