# Finding Max and Min values from string args

• 03-21-2012, 10:57 AM
Mortus
Finding Max and Min values from string args
Hey all,

This is my first time posting here and my java knowledge is very limited, it doesn't go to far beyond hello world so apologies for any ignorance that ensues here. I have searched the forums here and google for my question but had little luck so I thought I would post.

The title pretty much says it all I am writing a small code that will be finding the mean, length, max and min values from the arguments given and printing them.

Thus far I have managed to code the length and mean but I am a little stuck on finding max and min values, any help would be much appreciated.

Below is my code

Code:

```  public static void main(String[] args) {                 int total = 0;                 for (int i = 0; i < args.length; i++) {                         total += Integer.parseInt(args[i])                         {                         }                 }                 System.out.println(args.length);                 System.out.println(total/(double)args.length);         }```
• 03-21-2012, 11:17 AM
Re: Finding Max and Min values from string args
I have to following code to get the minimum and maximum value from an array of integer:

Code:

```import java.util.Arrays; import java.util.Collections; public class ArrayMinMax {     public static void main(String[] args)     {         Integer[] numbers = { 8, 2, 6, 7, 0, 1, 4, 9, 5, 3 };         int min = (int) Collections.min(Arrays.asList(numbers));         int max = (int) Collections.max(Arrays.asList(numbers));         System.out.println("Min number: " + min);         System.out.println("Max number: " + max);     } }```
Source: Learn Java by Examples - How do I know the minimum and maximum number in array?
• 03-21-2012, 11:41 AM
noobplus
Re: Finding Max and Min values from string args
Quote:

Originally Posted by Mortus
Code:

```total += Integer.parseInt(args[i])                         {                         }```

'total' cannot have a body because it is a variable

regards
dhilip
• 03-22-2012, 04:46 AM
DarrylBurke
Re: Finding Max and Min values from string args
Quote:

Originally Posted by noobplus
'total' cannot have a body because it is a variable

Meaning what exactly?

db
• 03-22-2012, 04:01 PM
noobplus
Re: Finding Max and Min values from string args
Quote:

Originally Posted by noobplus
'total' cannot have a body because it is a variable

regards
dhilip
Quote:

Originally Posted by DarrylBurke
Meaning what exactly?

db

I posted a coding following that post for the thread starter Mortus, but the codings were removed by some moderators,
:Edited -- sorry, I just found it. It was moved to here by some moderators
I had removed the body of 'total' in that codings
I was not about to mention that error anyway, but I mentioned that error before posting my code

regards
dhilip