【问题描述】
请编写一个方法实现如下功能: 输出任意三个整数 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();
}
}