---
title: "How to find the largest and smallest number among three input numbers using Ternary Operator"  
description: "Finding the largest and the smallest number among three input numbers can be done with the help of ternary operator in java. The program code is given"  
author: "Devesh Kumar Singh"  
published: 2015-11-18  
updated: 2018-03-13  
canonical: https://www.mindstick.com/blog/10987/how-to-find-the-largest-and-smallest-number-among-three-input-numbers-using-ternary-operator  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# How to find the largest and smallest number among three input numbers using Ternary Operator

Finding the largest and the [smallest](https://yourviews.mindstick.com/view/81880/royal-families-of-world-s-smallest-islands-do-fishing) number among three [input](https://www.mindstick.com/forum/159209/how-can-i-read-convert-an-input-stream-into-a-string-in-java) numbers can be done with the help of [ternary operator](https://www.mindstick.com/forum/12944/ternary-operator-in-razor-using-a-model) in java. The [program code](https://www.mindstick.com/interview/33814/what-will-be-the-output-of-following-program-code) is given below.\

```
 package program3;import java.io.*;public class Program3 {    public static void main(String[] args)throws IOException {        int a, b,c,l,s;        BufferedReader br= new BufferedReader (new InputStreamReader(System.in));        System.out.println("Enter first number");        a=Integer.parseInt(br.readLine());        System.out.println("Enter second number");        b=Integer.parseInt(br.readLine());        System.out.println("Enter third number");        c=Integer.parseInt(br.readLine());        l=a> b ? (a > c ? a : c) : (b > c ? b : c) ;        s=a< b ? (a < c ? a : c) : (b < c ? b : c) ;        System.out.println("Largest number is "+l);        System.out.println("Smallest number is "+s);    }}
```

##### This will produce the following output:

Enter first number

22

Enter [second](https://answers.mindstick.com/qa/41761/how-did-the-second-industrial-revolution-influence-women-s-roles-in-society) number

43

Enter [third](https://answers.mindstick.com/qa/94107/which-is-the-twenty-third-geostationary-communication-satellite-of-india-that-is-intended-to-extend-c-and-ku-band-transponders) number

90

Largest number is 90

Smallest number is 22

---

Original Source: https://www.mindstick.com/blog/10987/how-to-find-the-largest-and-smallest-number-among-three-input-numbers-using-ternary-operator

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
