开发者社区> 问答> 正文

输入 3 个数 a,b,c,按大小顺序输出

输入 3 个数 a,b,c,按大小顺序输出

展开
收起
珍宝珠 2020-02-13 17:59:04 2118 0
2 条回答
写回答
取消 提交回答
  • 下一站是幸福
    public class Four {
        public static void main(String[] args) {
            System.out.println("请输入a:");
            Scanner sc1 = new Scanner(System.in);
            int a = sc1.nextInt();
            System.out.println("请输入b:");
            Scanner sc2 = new Scanner(System.in);
            int b = sc2.nextInt();
            System.out.println("请输入c:");
            Scanner sc3 = new Scanner(System.in);
            int c = sc2.nextInt();
    
            if (a>b&&a>c&&b>c)
            {
                System.out.println(a+" "+b+" "+c);
            }else if (a>b&&a>c&&c>b)
            {
                System.out.println(a+" "+c+" "+b);
            }
            else if (b>a&&b>c&&a>c)
            {
                System.out.println(b+" "+a+" "+c);
            }
            else if(b>a&&b>c&&c>a)
            {
                System.out.println(b+" "+c+" "+a);
            }
            else if (c>a&&c>b&&a>b)
            {
                System.out.println(c+" "+a+" "+b);
            }
            else
            {
                System.out.println(c+" "+b+" "+a);
            }
        }
    }
    
    2020-03-15 22:22:42
    赞同 展开评论 打赏
  • package cskaoyan;
     
    public class cskaoyan34 {
        @org.junit.Test
        public void swap() {
            java.util.Scanner in = new java.util.Scanner(System.in);
            System.out.println("n1 = :");
            int n1 = in.nextInt();
            System.out.println("n2 = :");
            int n2 = in.nextInt();
            System.out.println("n3 = :");
            int n3 = in.nextInt();
     
            if (n1 > n2) {
                n1 = n1 ^ n2;
                n2 = n1 ^ n2;
                n1 = n1 ^ n2;
            }
     
            if (n1 > n3) {
                n1 = n1 ^ n3;
                n3 = n1 ^ n3;
                n1 = n1 ^ n3;
            }
     
            if (n2 > n3) {
                n2 = n2 ^ n3;
                n3 = n2 ^ n3;
                n2 = n2 ^ n3;
            }
     
            System.out.println(n1 + " " + n2 + " " + n3);
            in.close();
        }
    }
    
    2020-02-13 17:59:17
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
用计算和数据去改变整个世界 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载