public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("输入a:");
int a = scanner.nextInt();
System.out.print("输入b:");
int b = scanner.nextInt();
System.out.print("输入c:");
int c = scanner.nextInt();
System.out.print("输入d:");
int d = scanner.nextInt();
int maxAB, maxCD;
System.out.println("最大值是:" + ((maxAB = a > b ? a : b) > (maxCD = c > d ? c : d) ? maxAB : maxCD));
}
import java.util.Scanner;
public class Max_num {
public static void main(String[] args) {
int[] num;
Scanner in = new Scanner(System.in);
num = new int[4];
System.out.println("\n本程序可以找出四个整数的最大值。\n");
for (int i = 0; i < 4; ++i) {
System.out.printf("请输入第%d个数,%c = ", i + 1, 'a' + i);
num[i] = in.nextInt();
}
int max = num[0];
for (int i = 1; i < 4; ++i)
max = num[i] > max ? num[i] : max;
System.out.println("\n这四个数的最大值为:" + max);
}
}
public class Test {
public static void main(String[] args) {
int a = 1;
int b = 5;
int c = 7;
int d = 3;
System.out.println(a < b ? (b < c ? (c < d ? d : c) : (b < d ? d : c)) : (a < c ? (c < d ? d : c) : (a < d ? a : c)));
}
int max = a > b ? a : b ;
max = max > c ? max : c ;
max = max > d ? max : d ;
System.out.println ( max + "" ) ;
没有说必须在一句内完成吧?
int x = a > b ? a : b ;
x = x > c ? x : c;
x = x ? d ? x : c;