三个数从小到大排序

三个数从小到大排序

描述
      现在要写一个程序,实现给三个数排序的功能

输入
      输入三个正整数


输出
      给输入的三个正整数排序


样例输入
      20 7 33


样例输出
      7 20 33


Java实现

import java.util.Scanner;
/**
 * @author InJavaWeTrust
 */
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int temp;
		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(a + " " + b + " " + c);
	}

}

猜你喜欢

转载自injavawetrust.iteye.com/blog/2295055