import java.io.IOException;
import java.math.BigDecimal;
import java.util.Scanner;
public class Main {
@SuppressWarnings({
"resource"})
public static void main(String[] args) throws IOException{
Scanner sc=new Scanner(System.in);
int a=sc.nextInt(),b=sc.nextInt(),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);
}
}
思路:由于只有三个,就不用冒泡排序等对于一堆数据进行排序的方法了。
关键点:注意顺序。先a和b排,再a和c排,确保a是最小的,然后比较b和c,这样就省时间了。