编写java程序,输入三个整数x,y,z,请把这三个数由小到大输出

编写java程序,输入三个整数x,y,z,请把这三个数由小到大输出
2024-11-16 08:25:51
推荐回答(4个)
回答1:

public void compare(int x, int y, int z){
    if(x < y){
        if(x < z){
            System.out.println(x);
            if(y < z){
                System.out.println(y);
                System.out.println(z);
            }else {
                System.out.println(z);
                System.out.println(y);            
            }
        }else {
            System.out.println(z);
            System.out.println(x);
            System.out.println(y);       
        }
        
    }else {
        if(y > z){
            System.out.println(z);
            System.out.println(y);
            System.out.println(x);
        }else {
            System.out.println(y);
            if(x < z){
                System.out.println(x);
                System.out.println(z);
            }else {
                System.out.println(z);
                System.out.println(x);          
            }         
        }  
   }
    
}

回答2:

1、

public static void main(String []args)
{
System.out.println("请输入三个整数:");
Scanner input=new Scanner(System.in);
 int []num =new int[3];
 num[0]=input.nextInt();
 num[1]=input.nextInt();
 num[2]=input.nextInt();
 Arrays.sort(num);
 for (int i = 0; i < num.length; i++) {
 System.out.println(num[i]);
}



2、运行效果

回答3:

回答4:

不对啊,我显示有两处错误