Last Updated: 28 May, 2022
Operators are special symbols that perform the specified operations. Each operator is responsible to perform some specific operation on variables or values and return a result. The operators are classified and listed according to precedence order.
Java supports the following types of operators:
The ternary operator is a conditional operator and it is a single line statement consisting of three parts as given below in the syntax.
The ternary operator is an alternative for using if-else and nested if-else statements.
Example 1 : A sample Java program of Ternary Operator
Output
Bigger Value : 20
Example 2 : Checking Even-Odd Number using Ternary operation
Output
===== Checking Number is Even or Odd =====
Enter any Number
20
20 is Even Number.
In Java, It is also possible to write a nested ternary operator means one ternary operator inside another ternary operator same as a nested if-else statement. Let's understand it through the example.
Example 3 : A sample Java program of Nested Ternary Operator
Output
Largest Number: 80
That's all guys, hope this Java article is helpful for you.
Happy Learning... 😀
feedback@javabytechie.com