QUESTION IMAGE
Question
consider the following incomplete code. the missing method body should be ______. public class test { public static void main(string args) { system.out.println(f(5)); } public static int f(int number) { // missing body } } a system.out.println(
umber\); b return number; c return
umber\; d system.out.println(number);
Step1: Check return type
The method f is declared as public static int f(int number), which means it must return an int value.
Step2: Analyze each option
- Option A:
System.out.println("number");prints a string"number"and does not return anint. - Option B:
return number;returns anint(the parameternumberis of typeint). - Option C:
return "number";tries to return aString, which is not compatible with the return typeint. - Option D:
System.out.println(number);prints anintvalue but does not return anint.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
B. return number;