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

Posted luckyBrown

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了运算符和表达式 分支结构 3 个数值进行升序排列相关的知识,希望对你有一定的参考价值。

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 个数值进行升序排列的主要内容,如果未能解决你的问题,请参考以下文章