编写程序,输入abc三个数,将他们从小到大的顺序排序
import java.util.Scanner;
public class LianXi12 {
public static void main(String[] kk) {
double a,b,c,t;
//从键盘输入三个数给abc
Scanner sc=new Scanner(System.in);
a=sc.nextDouble();
b=sc.nextDouble();
c=sc.nextDouble();
//比较ab,如果a<b,交换ab
if(a<b) {t=a; a=b; b=t;}
//比较ac,如果a<c,交换ac
if(a<c) {t=a; a=c; c=t;}
//比较bc,如果b>c,交换bc
if(b<c) {t=b; b=c; c=t;}
//按顺序输出abc
System.out.println(a+" " +b+" " +c);
}
}
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
int max = Math.max(a, Math.max(b, c));
int min = Math.min(a, Math.min(b, c));
// 中间的那个就是和减最大最小
int mid = a + b + c - max - min;
// 按序输出
System.out.println(min + ", " + mid + ", " + max);
}
}
测试输出: