While reading one of Java for beginners books I stumbled upon an exercise:
Write a program that takes three
int
values from the command line and prints them in ascending order. UseMath.min()
andMath.max()
.
The problem is that if
conditionals are not yet considered, so logically I can't use them.
I tried to use an answer to a similar question in C, but encountered not a statement
error.
public class three_sort
{
public static void main(String[] args)
{
int a = Integer.parseInt( args[0] );
int b = Integer.parseInt( args[1] );
int c = Integer.parseInt( args[2] );
int min = a;
(min > b) && (min = b); //finding minimum
(min > c) && (min = c);
System.out.println(min);
int i = a;
(b < max) && (b > min) && (i = b); // finding intermediate
(c < max) && (c > min) && (i = c);
System.out.println(i);
int max = a;
(max < b) && (max = b); //finding maximum
(max < c) && (max = c);
System.out.println(max);
}
}
And yes, I haven't used Math.min
and Math.max
, because with help of them I can find min and max, but can't find intermediate.
Does anybody have any idea how to solve this problem?