84.8k views
1 vote
Public int mystery(double y) {

double result = 3 + y / 10;
if( result > 10 ) {

return result;
} else {
return 0;
}
}

Which of the following calls, when run from the same class, would return 0?
1. mystery (40.0)
2. mystery (40)
3 mystery(400.0)

1 Answer

5 votes

Answer:

2. mystery (40)

Step-by-step explanation:

2. mystery (40) because the result is 3 + 40 / 10 = 3 + 4 = 7 which is less than 10 so it returns 0. the return statement is only executed if the condition is true. In this case, the condition is false because 3 + 40 / 10 is not greater than 10.

1. mystery (40.0) is not a valid call because the method is expecting an int and you are passing a double.

User Richleland
by
6.9k points