Your objective is to write a program based on recursion. Your program will ask the computer
user to enter in two numbers. You will create an if-else statement that checks if one of the two
numbers is greater than 20 then the program will print out “Not in range.â€
Example output:
X = 2
Y = 33
Not in range.
Else your program will execute the method “every2â€.
The method will be a recursion method. Your method will compose a base case and a recursive
case.
The base case will define if x greater y and if so return 0.
Example output:
X = 7
Y = 4
0
Now the whole objective of the code is to print the sum of every other 2 numbers the computer
user put in from 0 to 20. This means the program will add 2 to the x variable until it is greater
than the y, which will then stop the program because the base case has been reached.
Example:
If the computer user puts in 1 as the x and 11 as the y then your code should print out ‘36’.
Because 1 + 3 + 5 + 7 + 9 + 11 = 36.
This will be solved in the recursion case.
Re-cap
o Check the user input so that it is in the range of x < 20, and y < 20.
o If the variables are within range, call the “every2†method, a recursive method which will
add 2 to the x variable until it is larger than the y variable.
o Print out the results.