用java语言完成输入三个整数,按由小到大的顺序输出这三个数

用java语言完成输入三个整数,按由小到大的顺序输出这三个数,第1张

用java语言完成输入三个整数,按由小到大的顺序输出这三个数

public class work4 {
    public static void main(String[] args) {
        int num1, num2,num3;
        Scanner ss = new Scanner(System.in);
        System.out.println("请输入第一个数:");
        num1 = ss.nextInt();
        System.out.println("请输入第二个数:");
        num2 = ss.nextInt();
        System.out.println("请输入第三个数:");
        num3 = ss.nextInt();
        if (num1<= num2&&num2<=num3&&num1<= num3) {
            System.out.println("从小到大排列为:" + num1 + num2 + num3);
        }
        if (num1<= num2&&num1<=num3&&num3<= num2) {
            System.out.println("从小到大排列为:" + num1 + num3 + num2);
        }
        if (num3<= num2&&num2<=num1&&num3<= num1) {
            System.out.println("从小到大排列为:" + num3 + num2 + num1);
        }
        if (num3 <= num2&&num3<=num1&&num1<= num2) {
            System.out.println("从小到大排列为:" + num3 + num1 + num2);
        }
        if (num2<= num3&&num3<=num1&&num2<= num1) {
            System.out.println("从小到大排列为:" + num2 + num3 + num1);
        }
        if (num2<= num1&&num2<=num3&&num1<= num3){
            System.out.println("从小到大排列为:" + num2+num1+num3);
        }
    }
}

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/4744634.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-08
下一篇 2022-11-08

发表评论

登录后才能评论

评论列表(0条)

保存