案例:三个和尚(升级版)

案例:三个和尚(升级版)

//需求:有三个和尚他们的身高必须由测量得出(身高未知,由键盘录入),用程序实现获取这三个和尚的最高身高
import java.util.Scanner;
public class HelloWorld {
    
    
    public static void main (String[] args){
    
    
        Scanner sc = new Scanner(System.in);
        System.out.println(" 输入第一个和尚的身高:");
        int height1 = sc.nextInt();
        System.out.println(" 输入第二个和尚的身高:");
        int height2 = sc.nextInt();
        System.out.println(" 输入第三个和尚的身高:");
        int height3 = sc.nextInt();
        int tempHeight = height1 > height2?height1:height2;
        int maxheight = tempHeight > height3?tempHeight:height3;
        System.out.println("这三个和尚中身高最高的是:"+maxheight+"cm");
    }
}

猜你喜欢

转载自blog.csdn.net/taoyingle/article/details/115048880