how do i sort the five interger without array

thanks
[13 byte] By [debacaa] at [2007-11-26 13:19:09]
# 1
your welcome
mkoryaka at 2007-7-7 17:45:27 > top of Java-index,Java Essentials,New To Java...
# 2
>how do i sort the five interger without array?What do you mean? Do you have 5 int variables?
cotton.ma at 2007-7-7 17:45:27 > top of Java-index,Java Essentials,New To Java...
# 3
The five integer ("5") is already sorted.
BillKriegera at 2007-7-7 17:45:27 > top of Java-index,Java Essentials,New To Java...
# 4
I don't know why you have to do so.I can give you a clue:You can package the primitive type into wrapper object,and then put them into List collection. list collection is sorted.But array is the simplest to implement sorting
Jefferya at 2007-7-7 17:45:27 > top of Java-index,Java Essentials,New To Java...
# 5

public class Int5 {

private static final int min= Integer.MIN_VALUE;

private static int i1= 42, i2= 54, i3= 69, i4= 1, i5= 0;

private static int s1, s2, s3, s4, s5;

private static int max() {

return Math.max(i1, Math.max(i2, Math.max(i3, Math.max(i4, i5))));

}

private static void erase(int max) {

if (i1 == max) i1= min; else

if (i2 == max) i2= min; else

if (i3 == max) i3= min; else

if (i4 == max) i4= min; else

if (i5 == max) i5= min;

}

public static void main(String[] args) {

erase(s5= max());

erase(s4= max());

erase(s3= max());

erase(s2= max());

erase(s1= max());

System.out.println(s1+" "+s2+" "+s3+" "+s4+" "+s5+" ");

}

}

kind regards,

Jos (< I must be a loony ;-)

JosAHa at 2007-7-7 17:45:27 > top of Java-index,Java Essentials,New To Java...
# 6
well...there is always the arraylist
pokaria at 2007-7-7 17:45:27 > top of Java-index,Java Essentials,New To Java...