Answer to Question #322465 in Java | JSP | JSF for Onai Maxwell

Question #322465

a. Critically explain why you would consider the concept of using methods in your program again running a couple of if-else statements.


b. Declare a method with three arguments all of the type int. The method should return the greatest of the three arguments, however, if any two or all three are the same, your method should return that value.


c. Embed your method in a complete program that requests for three variables all of the types int and displays the conditions explained in “b” above. 


1
Expert's answer
2022-04-02T09:59:48-0400
import java.util.Scanner;

/*
The if-else construct is used to choose between two courses of action depending on whether a given condition is true or false.

The if-else statement is always a choice between two alternatives
 */

public class Main {

    public static int ThreeNum(int fir, int sec, int the){
        int rez;

        if(fir > sec){
            if(fir>the){
                rez = fir;
            } else {
                rez = the;
            }
        } else {
            if(sec > the){
                rez = sec;
            } else {
                rez = the;
            }
        }

        if(fir == sec & sec == the & fir == the){
            rez = fir;
        } else {
            if(fir == sec)
                rez = fir;
            if(sec == the)
                rez = sec;
            if(the == fir)
                rez = the;
        }
        return rez;
    }
    
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);

        System.out.println(Main.ThreeNum(5,9,5));

    }
}

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