首页 > 其他 > 详细

运算符和表达式 、 分支结构 3 个数值进行升序排列

时间:2016-09-04 23:38:09      阅读:144      评论:0      收藏:0      [点我收藏+]
import java.util.Scanner;
public class SortOfThree {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请依次输入三个整数:a,b,c(以空格隔开)");
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        scanner.close();
        System.out.println("您输入的是:");
        System.out.println("a=" + a + ", b=" + b + ", c=" + c);
        int temp = 0;
        if (a > b) {
            temp = a;
            a = b;
            b = temp;
        }
        if (a > c) {
            temp = a;
            a = c;
            c = temp;
        }
        if (b > c) {
            temp = b;
            b = c;
            c = temp;
        }
        System.out.println("升序排列后,结果为:");
        System.out.println("a=" + a + ", b=" + b + ", c=" + c);
    }
}

 

运算符和表达式 、 分支结构 3 个数值进行升序排列

原文:http://www.cnblogs.com/luckyBrown/p/5840497.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!