Question: Write a recursive method printRange that takes integer parameters x and y and returns a String of the the sequential integers between x and y
Write a recursive method printRange that takes integer parameters x and y and returns a String of the the sequential integers between x and y inclusive. The first half should be seperated by ">" while and second half should be seperated by "<".
printRange(2, 8); // returns "2 > 3 > 4 > 5 < 6 < 7 < 8"
printRange(11, 19); // returns "11 > 12 > 13 > 14 > 15 < 16 < 17 < 18 < 19"
printRange(-2, -2); // returns "-2"
printRange(1, 10); // returns "1 > 2 > 3 > 4 > 5 - 6 < 7 < 8 < 9 < 10"
printRange(15, 16); // returns "15 - 16"
The method should throw an IllegalArgumentException if x is greater than y.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
