Java program for finding smallest number between 3 number

Java program for finding minimum number between 3 number

java code for finding min of 3

Program:-

import java.util.Scanner;

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

Output:-

Enter 1st number
56
Enter 2nd number
98
Enter 3rd number
41
The smallest number:41


Enter 1st number
47
Enter 2nd number
61
Enter 3rd number
89
The smallest number:47


Enter 1st number
45
Enter 2nd number
21
Enter 3rd number
84
The smallest number:21


Enter 1st number
55
Enter 2nd number
55
Enter 3rd number
48
The smallest number:48

Leave reply

Add your comments here

Back to Top