Techtopz is a blog on programming and tech stuff.
Techtopz is now on UpHub.
Follow us for more updates.


Java Programming | Smallest Number

This is a tutorial for smallest number in java. The program takes two numbers from user and decides the smallest number and prints it. The program is extendable. Go enjoy the program. Lets begin…

Program for smallest number in java.

//import Scanner as we require it.
import java.util.Scanner;

// the name of our class its public
public class SmallestNo {
//void main
public static void main (String[] args)
//declare int
int a,b;
//print message
System.out.println("Enter two numbers:");
//Take input
Scanner input = new Scanner(;
a = input.nextInt();
b = input.nextInt();
//if else statement
System.out.println(a+" is smallest");
System.out.println(b+" is smallest");


Enter two numbers:
12 is smallest

How it works
1. The program prints the message to enter two number.
2. The user enters two numbers.
3. If-else statement decides the smallest number and prints it.

Extending it
The program can be extended by using more numbers and finding the smallest out of them. Go extend it.

1. Import the Scanner.
2. Declare the class as public
3. Add the void main function
4. Add system.out.println() function with the message to enter two numbers.
5. Declare input as Scanner.
6. Take the inputs and save it in variables.
7. Add a if-else statement to find the smallest number.
8. Add system.out.println() function to print the number.

At the end.
You learnt creating the Java program for Smallest number. So now enjoy the program.

Login to like the post