要求


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

实施


package com.sy.pm;
import java.util.Scanner;

public class Test9 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        double x = 0;
        double y = 0;
        double z = 0;

        x = in.nextLong();
        y = in.nextLong();
        z = in.nextLong();
        String msg = "";

        //方法1
        if (x < y && x < z){
            if(y > z){
                msg = x+"<"+z+"<"+y;
            }else {
                msg = x+"<"+y+"<"+z;
            }
        }else  if(y < x && y < z) {
            if (x > z) {
                msg = y + "<" + z + "<" + x;
            } else {
                msg = y + "<" + x + "<" + z;
            }
        }else  {
            if(x < y){
                msg = z+"<"+x+"<"+y;
            }else{
                msg = z+"<"+y+"<"+x;
            }
        }
        System.out.println(msg);

        //方法2
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();

        if (a > b){
            int temp = a;
            a = b;
            b = temp;
        }

        if (a > c){
            int temp = a;
            a = c;
            c = temp;
        }

        if (b > c){
            int temp = b;
            c = b;
            b = temp;
        }

        System.out.println(a+" "+b+" "+c);

    }
}
我的文章对您有帮助吗?
我很可爱 请给我钱
扫一扫拿红包 → 扫商家收款码 → 花呗支付比红包多1分钱的金额
既可免费赞赏,又可完成支付宝支付任务!
最后修改:2020 年 02 月 28 日
如果觉得我的文章对你有用,请随意赞赏