File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Finding maximum value from command line arguments. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Finding maximum value from command line arguments." Watch "Finding maximum value from command line arguments." New topic
Author

Finding maximum value from command line arguments.

Tom Zanoli
Greenhorn

Joined: Aug 09, 2011
Posts: 5
Hi,
I have been struggling with this for several days and would appreciate any insight. Trying to call a method from main that reads string of arguments and determines maximum value. I cannot figure out why the below doesnt work. It appears that when I do the numbers conversion, it doesnt convert it to an array. Thanks,

Tom
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

Your code is not compilable.
numbers seems to be int[] but not defined anywhere.
And if you just want to find the max value, why would you need to store all the converted integers?
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

And ItDoesntWorkIsUseless
You are using number as an array at few places and as an int at some place. Moreover you haven't declared the int[] number.


Mohamed Sanaulla | My Blog
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38357
    
  23
And you can't re-declare numbers like that.
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 557
Here's what you could do:

Use the String array args as the argument to your findMax() method - Done
Then in the findMax() method:
1. Assign the first integer value of the array to a new int, maxValue
2. Compare the other integer values of the array to maxValue, and
a. if a greater value is found, the greater value becomes the new maxValue
3. Repeat step 2 until all array members have been checked.
4. Report maxValue as the largest integer.


Learning Java using Eclipse on OpenSUSE 11.2
Linux user#: 501795
Tom Zanoli
Greenhorn

Joined: Aug 09, 2011
Posts: 5
Thanks everyone. The main issue I cant get my head around is how do you convert the string array to integer array. I cannot assign a string array value to a new int. Thanks.
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11229
    
  16

i don't think you can convert a String array to an Integer (or int) array. You can, however, convert a String to an Int. you can iterate through a String array, converting them one at a time to Integers, then insert those into your Integer array.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Tom Zanoli
Greenhorn

Joined: Aug 09, 2011
Posts: 5
OK that makes sense. Thanks a lot. I still don't quite get how to iterate through since it is not an array.
Greg Brannon
Bartender

Joined: Oct 24, 2010
Posts: 557
I'm don't know that you need an int[] array. If I suggested you do, I didn't mean to. You only need to consider the integer values of your String[] array one at a time to find the largest one.
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

Tom Zanoli wrote:OK that makes sense. Thanks a lot. I still don't quite get how to iterate through since it is not an array.

What is the it you are referring given you have String array and int array?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Finding maximum value from command line arguments.