码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2016-09-04 23:40:22      阅读:153      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!