Answer to Question #314070 in Java | JSP | JSF for rana

Question #314070

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 


1
Expert's answer
2022-03-18T15:33:06-0400
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();
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS