CGZY2.5 请编写一个方法实现如下功能: 输出任意三个整数 a,b,c中最大的一个(双重判断/三目运算符)

该代码示例展示了如何用Java编程语言找出并打印出三个输入整数中的最大值。通过使用条件运算符,实现了简洁的比较逻辑,确保了效率。此程序适用于基础的数值比较操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

【问题描述】
请编写一个方法实现如下功能: 输出任意三个整数 a,b,c中最大的一个,并打印出来。
【输入形式】
Please input the first number:
Please input the second number:
Please input the third number:
【输出形式】
The maximum number is:
【输入样例】
5
7
10
【输出样例】
10

重点:
双重判断==三目运算符

import java.util.Scanner;

public class Main25 
{

	public static void main(String[] args) 
	{
		 Scanner sc = new Scanner(System.in);
		 System.out.print("Please input the first number:\n");
		 int a = sc.nextInt();
	     System.out.print("Please input the second number:\n");
	     int b = sc.nextInt();
	     System.out.print("Please input the third number:\n");
	     int c = sc.nextInt();
	     int max = a>b? (a>c? a:c):(b>c? b:c);
	     System.out.println("The maximum number is:"+max);
	     sc.close();
	}

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值