URI Online Judge | 1042
Simple Sort
Adapted by Neilor Tonin, URI Brazil
Timelimit: 1
Read three integers and sort them in ascending order. After, print these values in ascending order, a blank line and then the values in the sequence as they were readed.
Input
The input contains three integer numbers.
Output
Present the output as requested above.
Input Sample | Output Sample |
7 21 -14 | -14 7 21 7 21 -14 |
-14 21 7 | -14 7 21 -14 21 7 |
URI 1042 Solution in Java Language
import java.util.Scanner;
public class URI_1042 {
public static void main(String[] args) {
int X, Y, Z, min1, min2 = 0, min3 = 0;
Scanner input = new Scanner(System.in);
X = input.nextInt();
Y = input.nextInt();
Z = input.nextInt();
min1 = Math.min(X, Math.min(Y, Z));
if (min1 == X) {
min2 =Math.min(Y, Z);
min3 =Math.max(Y, Z);
}
if (min1 == Y) {
min2 =Math.min(X, Z);
min3 =Math.max(X, Z);
}
if (min1 == Z) {
min2 = Math.min(X, Y);
min3 = Math.max(X, Y);
}
System.out.print(min1+"\n"+min2+"\n"+min3+"\n\n");
System.out.print(X+"\n"+Y+"\n"+Z+"\n");
}
}
No comments:
Write commentsTo know more about the problem, give us your valuable commment. We'll try to help you. Thanks