003-006-005

Conditional Expressions with Ternary Operator

Medium

Problem Description

Conditional Expressions with Ternary operator

In this problem, you will create a program that reads two integers and uses the ternary operator (condition ? value1 : value2) to compute the maximum, minimum, and sign of the first integer, and displays the result to standard output.

Learning Objective: Understand Java's ternary operator (condition ? value1 : value2) and write concise conditional expressions

Overview

Create a program that inputs two integers and uses the ternary operator to find maximum, minimum, and sign.

Specifications

  1. Input two integers a and b
  2. Using ternary operator:
    • Output the maximum of a and b
    • Output the minimum of a and b
    • Output "positive" if a is positive, "non-positive" otherwise

Input Format

15 8

Output Format

Max: 15
Min: 8
Sign of a: positive

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up