三个和尚比身高进阶版
题目:寺庙中住着三位和尚,他们的身高必须经过测量得知,请用程序实现获取这三个和尚的最高身高。
使用scanner和三元运算符获取三个和尚的最高身高
代码:
import java.util.Scanner;//导入包
public class ThreeScannerDemo {
public static void main(String[] args) {
System.out.println("请输入三个和尚的身高:");
Scanner sc = new Scanner(System.in);//创建对象
Double height1 = sc.nextDouble();
Double height2 = sc.nextDouble();
Double height3 = sc.nextDouble();
Double i = height1 > height2?height1 : height2;
Double max = i > height3 ? i : height3;
System.out.println("三个和尚中最高的为:"+max+"cm");
}
}
运行截图: