Question: 1. Insert the missing statement in the following code fragment. The method is designed to compute the area of a circle with the radius given
1. Insert the missing statement in the following code fragment. The method is designed to compute the area of a circle with the radius given as argument. public static double circleArea(double radius) { double area = Math.PI * radius * radius; _______________________ }
return radius;
return area;
circleArea = area;
return circleArea;
2.True or false? a) A method has exactly one return statement.
b) A method has at least one return statement.
c) A method has at most one return value.
d) A method with return value void never has a return statement.
e) When executing a return statement, the method exits immediately.
f) A method with return value void must print a result.
g) A method without parameter variables always returns the same value.
3.In the program below, which of the variables must be renamed to avoid overlapping scopes?
public static int computeResult(int value) { int result = 1; // Line 3 for (int k = 1; k <= value; ++k) { int value = result * k; // Line 6 } int k = value * 2; // Line 8 return result * k; } public static void main(String[] args) { int value = 5; // Line 14 int result = computeResult(value); }
The value variable declared on line 14.
The k variable declared on line 8.
The result variable declared on line 3.
The value variable declared on line 6.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
