java经典问题__将三个数从小到大输出

来源:互联网 发布:rpc 135端口 修改 编辑:程序博客网 时间:2024/06/17 07:08

题目:输入三个整数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();}}


原创粉丝点击