| Author |
how to modify this program to get asending order integers?
|
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
i want to enter integer command line arguments and get it arranged in ascending order
[ September 24, 2008: Message edited by: Bear Bibeault ]
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Well, what have you tried so far? And what problems are you currently running into? Henry
|
Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
|
 |
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
i only now know is that i enter command line arguments which are integers and program is printing in the same order. what i want is to print in ascending order. so how to modify this??
|
 |
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
since we are taking the values from command line we cant use collection classes i guess??
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Originally posted by yuvraj kotegar: i only now know is that i enter command line arguments which are integers and program is printing in the same order. what i want is to print in ascending order. so how to modify this??
JavaRanch is a learning site. It is against policy to do someone's homework. We can give you hints when you run into issues, but you must start it, and you must actually do most of the work. So, what have you attempted so far? And if you have not, where would be the best place to start? Meaning what codes do you think you would need? Henry
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Originally posted by yuvraj kotegar: since we are taking the values from command line we cant use collection classes i guess??
Why not? How would you convert an array of strings into a collection of strings (or integers)? Henry
|
 |
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
int a=Integer.parseInt(); i know it. but how do you put a array of integers in it??
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
Originally posted by yuvraj kotegar: int a=Integer.parseInt(); i know it. but how do you put a array of integers in it??
In an int? Well, obviously you can't... But how do you declare an array of ints? Henry
|
 |
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
int a[] probably like this?? but how do i give the size here?? i mean i dont know how many values i am entering in command line!!
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Sure you do. Just look at args.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
but how do i give the size here?? i mean i dont know how many values i am entering in command line!!
You do know that you are asking the next questions already. You can actually ask yourself the question and figure it out -- or you can wait for me to parrot you... Anyway... how do you figure out how many parameters are entered in the command line? Henry
|
 |
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
args.length is it??
|
 |
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
this is the modified logic
[edit]Correct indentation. CR[/edit] [ September 25, 2008: Message edited by: Campbell Ritchie ]
|
 |
Henry Wong
author
Sheriff
Joined: Sep 28, 2004
Posts: 16695
|
|
this is the modified logic
Well, did it compile? And if it did, did it work? Henry
|
 |
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
no am getting a error with this line arr=Integer.parseInt(args[i]); what to do?? am not getting idea
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
You have called your array "arr" and you are trying to put an int into the array; you really ought to be putting the int into a particular member of that array. And please indent code inside the code tags (better to use ctrl-c ctrl-v) because it makes it easier to read; I shall edit your last post so you can see the difference.
|
 |
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
|
how to send the input command line parmaters into the Array.sort() method.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
Well your code is already quite good, if you fix two lines: You want to set and read only one specific element of the array, not the entire array. You've already shown you know how to read an array element, setting it is not that different.
|
 |
yuvraj kotegar
Ranch Hand
Joined: Jul 31, 2008
Posts: 120
|
|
it's working fine now. i have fixed it. Thanks people
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32708
|
|
Well done, and you're welcome
|
 |
 |
|
|
subject: how to modify this program to get asending order integers?
|
|
|