# Java program to find smallest of the three numbers using ternary operators

Java Programming Java8Object Oriented Programming

#### Complete Java Programming Fundamentals With Sample Projects

98 Lectures 7.5 hours

#### C Programming from scratch- Master C Programming

Best Seller

60 Lectures 8 hours

#### C++ Programming

238 Lectures 56.5 hours

The conditional operator is also known as the ternary operator. This operator consists of three operands and is used to evaluate Boolean expressions. The goal of the operator is to decide, which value should be assigned to the variable. The operator is written as −

variable x = (expression) ? value if true: value if false

## Example

Live Demo

public class SmallestOf3NumsUsingTernary {
public static void main(String args[]) {
int a, b, c, temp, result;
a = 10;
b = 20;
c = 30;
temp = a > b ? a:b;
result = c > temp ? c:temp;
System.out.println("Smallest number is ::"+result);
}
}

## Output

Smallest number is ::10
Updated on 13-Mar-2020 09:59:17