用Java三元运算符写代码输入三个整数排序从大到小输出
时间: 2023-03-30 13:03:12 浏览: 122
java代码-输入三个数,按从大到小输出
可以的,以下是代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
int max = a > b ? (a > c ? a : c) : (b > c ? b : c);
int min = a < b ? (a < c ? a : c) : (b < c ? b : c);
int mid = (a + b + c) - max - min;
System.out.println(max + " " + mid + " " + min);
}
}
阅读全文