Write a Java method to find the smallest number among three numbers.
Test Data:
Input the first number: 25
Input the Second number: 37
Input the third number: 29
import java.util.Scanner;
public class Testing {
public void FindMinNumber(){
Scanner in = new Scanner(System.in);
System.out.print("Input the first number: ");
int FirstNum = in.nextInt();
System.out.print("Input the second number: ");
int SecondNum = in.nextInt();
System.out.print("Input the third number: ");
int ThirdNum = in.nextInt();
if(FirstNum < SecondNum){
if(FirstNum < ThirdNum){
System.out.print("The first number is the minimum: " + FirstNum);
} else {
System.out.print("The third number is the minimum: " + ThirdNum);
}
} else {
if(SecondNum < ThirdNum){
System.out.print("The second number is the minimum: " + SecondNum);
} else {
System.out.print("The third number is the minimum: " + ThirdNum);
}
}
}
public static void main(String[] args) {
Testing objTest = new Testing();
objTest.FindMinNumber();
}
}
Comments
Leave a comment