Java返回3个数的最大值
class Max {
public static void main(String[] args) {
//②获取三个数的最大值
Scanner input = new Scanner(System.in);
System.out.println("请输入3个数字");
int s1 = input.nextInt();
int s2 = input.nextInt();
int s3 = input.nextInt();
int max1 = (s1 > s2) ? s1 : s2;
int max = (s3 > max1) ? s3 : max1;
System.out.println(max);
}
}
class puls{
//⑥三元运算符 (条件表达式)?表达式1:表达式2
//三元运算符的嵌套使用
int s,q;
s=q=10;
String MaxString = (s>q)? "s更大" : ((s == q)? "s和q相等" : "s小于q");
System.out.println(MaxString);
}