Java学习_004 数据输入:案例2

发布时间 2023-09-08 21:25:21作者: 一切推倒重来

需求:三个和尚的身高需要手动输入,请用程序实现这三个和尚的最高身高。

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int height1 = sc.nextInt();
        int height2 = sc.nextInt();
        int height3 = sc.nextInt();
        int tempHeight = height1 > height2 ? height1 : height2;
        int maxHeight = tempHeight > height3 ? tempHeight : height3;

        System.out.println("maxHeight:"+maxHeight);
        }
    }

结果: