Reputation: 51
I have a sorting basic problem:
Write a program called Sort that will take a sorting order followed by a list of numbers from the commandline and print out the sorted list of numbers
for example : java Sort asc 12 2 3 -9 8
and output is
-9 2 3 8 12
and the opposite if I write "desc" and the numbers.
My problem is: how do I tell my program to which function should it go? I only know how to send it to each function, but not to one of them.
I don't have problem with the sorting just telling the program which function to do.
Upvotes: 0
Views: 148
Reputation: 695
For telling your program to which function should it go you can use if else statement, the function will act according to the argument "asc" or "desc":
if(args[0].equals("asc")) {
...
}
else {
...
}
Upvotes: 2