Question: Given that the following method definition belongs to a class. [1 mark] int evaluate(int x) { if (x == 1) return 1; else return x
Given that the following method definition belongs to a class. [1 mark]
|
int evaluate(int x) { if (x == 1) return 1; else return x + evaluate(x-1) ; }
|
What is displayed when the following statement is called?
System.out.println("The result is " + evaluate( 5) );
Select one:
a. 5 4 3 2 1
b. 21
c. 5 4 3 2 1 0
d. The code will not compile because the keyword, if, wants the associated keyword, else.
e. 15
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
