-
Whats wrong with this?
Code:
import java.io.*;
public class sortem{
public static void main(int args[]) throws IOException {
int i=9, min=100, prevMin=0;
while (i > 0)
{
int index=9;
while (index >= 0)
{
if ((args[index] < min) && (args[index] > prevMin))
min = args[index];
index--;
}
System.out.println( min );
prevMin = min;
min = 100;
i--;
}
}
}
-
Well ...
I don't have Java here, so I can't test the code. But you seem to be doing a sort on 9 numbers entered through command line arguments. What problems are you facing?
Two possible reasons could be accepting an int array instead of a String one in the psv main method, and typecasting the array elements when comparing or assigning.
.
-
honeybee is rignt you would have to change the parameter of the main method to take a string array instead of an int array.
Your program will compile fine with the int array in the main method but a java.lang.NoSuchMethodError will be prooduced at runtime.
-
Once you change the int array into a String array i would use the parseInt() method from the Integer class for the comparison.
Code:
if ((Integer.parseInt(args[index]) < min && Integer.parseInt(args[index]) > prevMin);