# Thread: Finding Max and Min values from string args

1. Member
Join Date
Mar 2012
Posts
1
Rep Power
0

## 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

Java 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);
}```

2. Senior Member
Join Date
Jun 2007
Location
Bali, Indonesia
Posts
762
Rep Power
10

## 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:

Java 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?

3. ## Re: Finding Max and Min values from string args

Originally Posted by Mortus
Java Code:
```total += Integer.parseInt(args[i])
{
}```
'total' cannot have a body because it is a variable

regards
dhilip

4. ## Re: Finding Max and Min values from string args

Originally Posted by noobplus
'total' cannot have a body because it is a variable
Meaning what exactly?

db

5. ## Re: Finding Max and Min values from string args

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

regards
dhilip
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
Last edited by noobplus; 03-22-2012 at 04:10 PM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•