对三个数字进行排序

题目要求

对三个数字进行排序
使用键盘输入三个数字,然后按降序显示它们。
所显示的数字必须用空格分隔。

Requirements:

  1. 程序应从键盘读取这些数字。
  2. 程序应在屏幕上显示数字。
  3. 程序应显示用空格分隔的三个数字。
  4. 程序应按降序显示数字。

代码

package zh.codegym.task.task04.task0420;

/* 
对三个数字进行排序
*/

import java.io.*;

public class Solution {
    public static void main(String[] args) throws Exception {
        //在此编写你的代码
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int a = Integer.parseInt(reader.readLine());
        int b = Integer.parseInt(reader.readLine());
        int c = Integer.parseInt(reader.readLine());
        if (a <= b && a <= c) {
            if (b <= c) {
                System.out.println(c + " " + b + " " + a);
            } else {
                System.out.println(b + " " + c + " " + a);
            }
        } else if (b <= a && b <= c) {
            if (a <= c) {
                System.out.println(c + " " + a + " " + b);
            } else {
                System.out.println(a + " " + c + " " + b);
            }
        } else  //c is minimum
        {
            if (a <= b) {
                System.out.println(b + " " + a + " " + c);
            } else {
                System.out.println(a + " " + b + " " + c);
            }
        }
    }
}


逆风而行。

@侧耳听智慧,专心求聪明 Turnging your ear to wisdom and applying your heart to understanding!