思路:
1.获取到键盘输入的三个数字
2.先比较其中两个的大小,并找到其中最大的
3.将步骤2中找到的最大的和第三个数比较,并找到其中最大
4.那么步骤3找到的便是最大的。
代码:
public class Demo1 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入三个数:");
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
int temp = (a>b)?a:b;
int max = (temp>c)?temp:c;
System.out.println("最大的数是:"+max);
}
}
运行结果: