108k views
0 votes
What is the returned by the call go(8) ?

public static String go(int x)
{
if (x==5)
return "same";
else if (x>8)
return "notsame";
return "done";
}

User Newnomad
by
8.3k points

1 Answer

1 vote

Final answer:

The call go(8) will return "done" since the input 8 does not satisfy either of the if or else if conditions in the provided Java method.

Step-by-step explanation:

The student asked about the result of a method call in a piece of Java code. The given code is:

public static String go(int x){
if (x==5) return "same";
else if (x>8) return "notsame";
return "done";
}

When go(8) is called, the method will check the value of x. Since x is compared to 5 and 8, and it is not equal to 5 or greater than 8, neither the first (if) nor the second (else if) condition is met. Therefore, the method will execute the last return statement, which is "done".

User Greim
by
8.7k points