蓝桥杯 算法训练 排序

版权声明:对您有帮助的话,求您免费的关注和点赞 https://blog.csdn.net/weixin_42069140/article/details/89717072

问题描述

  编写一个程序,输入3个整数,然后程序将对这三个整数按照从大到小进行排列。
  输入格式:输入只有一行,即三个整数,中间用空格隔开。
  输出格式:输出只有一行,即排序后的结果。
  输入输出样例

样例输入

9 2 30

样例输出

30 9 2

时间限制:1.0s  

内存限制:512.0MB

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();
		if(a < b) {
			int temp = a;
			a = b;
			b = temp;
		}
		if(a < c) {
			int temp = a;
			a = c;
			c = temp;
		}
		if(b < c) {
			int temp = b;
			b = c;
			c = temp;
		}
		System.out.println(a + " " + b + " " + c);
		s.close();
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42069140/article/details/89717072