Results 1 to 5 of 5
- 03-21-2012, 09:57 AM #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
Thanks in advance!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); }
- 03-21-2012, 10:17 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 696
- Rep Power
- 6
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:
Source: Learn Java by Examples - How do I know the minimum and maximum number in array?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); } }Website: Learn Java by Examples
- 03-21-2012, 10:41 AM #3
Re: Finding Max and Min values from string args
- 03-22-2012, 03:46 AM #4
- 03-22-2012, 03:01 PM #5
Re: Finding Max and Min values from string args
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
dhilipLast edited by noobplus; 03-22-2012 at 03:10 PM.
Similar Threads
-
use of String[] args
By mallikanala in forum New To JavaReplies: 1Last Post: 06-21-2011, 08:09 AM -
Passing values to main(String args[]) ?
By al_Marshy_1981 in forum New To JavaReplies: 6Last Post: 02-21-2010, 10:16 PM -
String, quotes and args
By mac in forum New To JavaReplies: 8Last Post: 02-04-2010, 04:24 PM -
What does String args[] stand for?
By Addez in forum New To JavaReplies: 7Last Post: 08-19-2009, 10:24 AM -
Why can't we write main without String args[]
By shailender in forum New To JavaReplies: 4Last Post: 11-05-2008, 10:58 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks