首页 > 技术文章 > Java 实现键盘输入三个数字求出最大值

wangchw 2021-01-13 21:01 原文

public class Demo02ScannerSum {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入第一个数字:");
        int a = sc.nextInt();
        System.out.println("请输入第二个数字:");
        int b = sc.nextInt();
        System.out.println("请输入第三个数字:");
        int c = sc.nextInt();
        //首先得到前两个最大值
        int temp = a > b ? a : b;
        //再让原来的最大值和第三个值对比
        int temp2 = temp > c ? temp : c;
        System.out.println("最大值为"+temp2);
    }
}

 

推荐阅读