Java program to find Smallest number between 2 numbers

Java program to find Smallest number between 2 numbers

Program:-

import java.util.Scanner;

class group{
public static void main(String ang[]){
Scanner data= new Scanner(System.in);
int num1, num2;
// Read 1st number
System.out.println("Enter 1st number");
num1=data.nextInt();
// Read 2nd number
System.out.println("Enter 2nd number");
num2=data.nextInt();
// Find smallest number
if(num1>num2)
System.out.println("The smallest number:"+num2);
else
System.out.println("The smallest number:"+num1);
}
}

Output:-

Enter 1st number
2
Enter 2nd number
1
The smallest number:1

Output:-

Enter 1st number
54
Enter 2nd number
54
The smallest number:54

Output:-

Enter 1st number
-25
Enter 2nd number
26
The smallest number:-25

Output:-

Enter 1st number
25
Enter 2nd number
-69
The smallest number:-69



Learn Java:-
Java codes

Java Programs:-
List of Java Programs

Leave reply

Add your comments here

Back to Top