题目:输入三个整数x,y,z,请把这三个数由小到大输出。
public class Practise15 {
public void sort(){
Scanner scan = new Scanner(System.in);
System.out.println("x=");
int x = scan.nextInt();
System.out.println("y=");
int y = scan.nextInt();
System.out.println("z=");
int z = scan.nextInt();
int temp;
if(x > y){
temp = y;
y = x;
x = temp;
}//从小到大:x y(x 与 y的顺序排列好了)
if(x > z){
System.out.println(z + " "+ x + " " + y);
}else{
if(y < z){
System.out.println(x + " "+ y + " " + z);
}else{
System.out.println(x + " "+ z + " " + y);
}
}
}
public static void main(String[] args) {
(new Practise15()).sort();
}
}