005-005-001
Ternary Operator: Max Value
Easy
Problem Description
Ternary operator: Max Value
In this problem, you will create a program that reads two integers using Scanner, finds the maximum value in one line using the ternary operator (? :), and displays the result to standard output.
Learning Objective: Judge concisely with ternary operator
Create program that inputs two numbers and displays the larger one. Find max value in one line using ternary operator (? :).
Input
Line 1: First number (integer)
Line 2: Second number (integer)
Output
First: [num1]
Second: [num2]
Larger: [max]
```java
## Examples
### Example 1: First is larger
Input:
```java
50
30
```java
Output:
```java
First: 50
Second: 30
Larger: 50
```java
### Example 2: Second is larger
Input:
```java
20
40
```java
Output:
```java
First: 20
Second: 40
Larger: 40
```java
### Example 3: Equal values
Input:
```java
30
30
```java
Output:
```java
First: 30
Second: 30
Larger: 30
Test Cases
※ Output examples follow programming industry standards
Normal case
Input:
100 75
Expected Output:
First: 100 Second: 75 Larger: 100
Normal case
Input:
15 99
Expected Output:
First: 15 Second: 99 Larger: 99
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here
sc.close();
}
}
0 B / 5 MB
You have 10 free executions remaining
