---
title: "How to find the largest and smallest number among three input number using Math.max() and Math.min()"  
description: "Finding the largest and the smallest number among three input numbers can be done with the help of max and min methods in java. These are math functio"  
author: "Devesh Kumar Singh"  
published: 2015-11-18  
updated: 2018-03-13  
canonical: https://www.mindstick.com/blog/10986/how-to-find-the-largest-and-smallest-number-among-three-input-number-using-math-max-and-math-min  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# How to find the largest and smallest number among three input number using Math.max() and Math.min()

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 max and min [methods](https://www.mindstick.com/articles/13060/runny-nose-remedy-methods-that-work-best) in java. These are math [functions](https://www.mindstick.com/forum/160140/explain-the-role-of-functions-as-a-service-faas-in-serverless-computing) provided by the Math [class](https://www.mindstick.com/blog/165/generic-class-in-c-sharp). The [program code](https://www.mindstick.com/interview/33814/what-will-be-the-output-of-following-program-code) is given below.\

```
 package program2;import java.io.*;public class Program2 {    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=Math.max(Math.max(a,b), c);                System.out.println("Largest number is "+ l);        s=Math.min(Math.min(a, b), c);        System.out.println("Smallest number is "+ s);            }}
```

##### It will produce the following Output:

Enter first number

45

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

3

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

76

Largest number is 76

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