Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(java: method and text files): what is the error in the following method definit

ID: 3623988 • Letter: #

Question

(java: method and text files): what is the error in the following method definition?
public static int find_min(int x, int y) 

 

{

 

    int min = 0;

 

    if (x

    {

 

        min = x;

 

    }

 

    else

 

    }

 

        min = y;

 

    }

 

}

 

a.the method returns the maxumum instead of the minimum of the two parameters.

 

b. the method does not return a value.

 

c. the method returns 0 if the first  and second parameters are equal.

 

d. the method does not specify a type for the second parameter.
 

 

 

 

                                  

 

                                     

 

                                       

 

                                   

 

 

 

 

Explanation / Answer

First of all the piece of code have some errors. If you tried to compile it you would get errors.

Apart from that, b seems to be the case.

Hope it helps you. Below is the code with comments and corrected

public static int find_min(int x, int y) {

int min = 0;
/** You didn't have any condition in your if statement */      

if (x < y) { min = x;}

else { min = y; }

// Your method didn't return anything before return min;

}