Java Program to find smallest of three numbers

Here we are explaining how to write a java program to find out the smallest of three numbers. So first we have to read three integer numbers from the user and by using an if-else statement we can find out the smallest number.

How to implement the java program to find out the smallest of three numbers?

First, we have to declare the class SmallestNumber.Then we have to declare the variables a,b,c to hold the three integer numbers. Then read the numbers from the user using the scanner class object. By using if condition check if a


STEP 1: Declare the class Smallest with a public modifier.

STEP 2: Open the main() to start the program, Java program execution starts with the main()

STEP 3: Declare the integer variables a,b,c.

STEP 4: Create the object of the scanner class as sc.

STEP 5: Read the three numbers into the variables a,b,c.

STEP 6: Check if a

STEP 7: Else check if b> c, if true then display the smallest number is b.

STEP 8: Else display the smallest number is c.



Java Source Code

                                          import java.util.Scanner;
public class SmallestNumber 
    public static void main(String[] args) 
        int a,b,c;
        Scanner sc = new Scanner(;
        System.out.println("Enter the first number:");
        a = sc.nextInt();
        System.out.println("Enter the second number:");
        b = sc.nextInt();
        System.out.println("Enter the third number:");
        c = sc.nextInt();
        if(a < b && a < c)
            System.out.println("The smallest number is:"+a);
        else if(b < c)
            System.out.println("The smallest number is:"+b);
            System.out.println(" The smallest number is:"+c);


Enter the first number:100
Enter the second number:105
Enter the third number:1
The smallest number is:1