Sort 3 int's WITHOUT an aray.
Hello everyone, I am new to the Java Forums (and Java itself) and so far, this site has been GREAT! I have been reading through some threads before, but now I need to ask a question so I thought it was time to create a profile!
On an assignment I am doing, the professor has asked us to write a method that takes 3 integers as its input parameters (int a, int b, int c), sort the int's in order, and return a string with the numbers in order. AND I CAN NOT USE AN ARRAY! I was going good until i read that part lol.
EXAMPLE: if (199, 8, 23) is passed, it should return "8 23 199".
So how would I do this? I just need help with the physical sorting part.
I started off with this just to get the first number, but it just doesnt feel right. There has to be a better way? And if this is the way, how would I get the second and third number in the correct order (least to highest)
public static String inOrder(int a, int b, int c){
String s = ("");
if (a < b && a < c){
s += (a + " ");
}
else if (b < a && b < c){
s += (b + " ");
}
else{
s += (c + " ");
}
return s;
}
Thanks in advanced for any help!