有三个整数a, b, c,由键盘输入, 输出其中最大的数.

思路:

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);
	}
}

运行结果:

发布了28 篇原创文章 · 获赞 5 · 访问量 5801

猜你喜欢

转载自blog.csdn.net/weixin_41879980/article/details/95855044