Font size
WorksheetsMethods
Total questions: 10
Worksheet time: 3mins
What do I put as the return type if I don't want to return anything from a method?
int
none
void
leave it empty!
True or False:
A method does not need to have any parameters.
True
False
What is the correct way to define a method that subtracts two numbers, returning the difference?
public static void subtract(int num1, int num2)
public static int subtract (int num1, int num2)
public static int subtract(String num1, String num2)
public static void subtract(int num1, num2)
Fill in the blank for defining a method that returns the square root of a number:
public static (a) squareRoot(double number);
Which of the following statements is false?
A method is good for reusing code.
A method with a return type must return a variable of that return type.
A method must always have at least 1 parameter.
A method with a void return type must not return anything.
Select all of the following code snippets that are correct for calling a method sum, which returns the sum of two numbers:
int sum = add(5, 7);
System.out.println(add(5,7));
add(5);
add(5,7);
Why is the following call to method minOfTwo, which returns the minimum number of 2 given numbers, incorrect?
int min = minOfTwo(8,"9");
The method minOfTwo only takes in one parameter.
The method minOfTwo does not return anything.
The method minOfTwo takes in two integers, but a String is being passed in.
There is nothing incorrect with this method call.
True or False:
There is something incorrect about the following call to the method minOfTwo:
int min = minOfTwo(int 8, int 9);
True
False
What is wrong with the following code snippet?
public static multiply(int a, int b) {
return a * b;
}
Nothing, it is correct.
It should return a String, not an integer.
It should not return anything.
It is missing the int return type in the method definition.
What will be printed from the following code snippet, where minOfTwo is a method that returns the minimum number?
System.out.println(minOfTwo(10,-1));
10
-1
Nothing, there is an error
minOfTwo(10,-1)
