输入三个整数x,y,z,请把这三个数由小到大输出。

package lianxi;
import java.util.*;
public class Sangeshupaixu {

    public static void main(String[] args) {
    System.out.println("请输入x的值:");
    Scanner shu1=new Scanner(System.in);
    int x=shu1.nextInt();
    System.out.println("请输入y的值:");
    Scanner shu2=new Scanner(System.in);
    int y=shu2.nextInt();
    System.out.println("请输入z的值:");
    Scanner shu3=new Scanner(System.in);
    int z=shu3.nextInt();
    int m=0;
    System.out.print("由小到大排序后的结果:");
    if (x<y&&x<z) 
    {
        System.out.print(x+" ");
        if(y<z)
        {
            System.out.print(y+" "+z);
        }
        else
        {
            System.out.print(z+" "+y);
        }
    }
    if (y<x&&y<z) 
    {
        System.out.print(y+" ");
        if(x<z)
        {
            System.out.print(x+" "+z);
        }
        else
        {
            System.out.print(z+" "+x);
        }
    }
    if (z<y&&z<x) 
    {
        System.out.print(z+" ");
        if(y<x)
        {
            System.out.print(y+" "+x);
        }
        else
        {
            System.out.print(x+" "+y);
        }
    }
    
    
    }

}

posted @ 2016-05-16 14:49  凌零聆  阅读(1901)  评论(0编辑  收藏  举报