Question: Write using Java a recursive method printBracketRanges that takes two integer parameters x and y and returns a String of the the sequential integers between

Write using Java a recursive method printBracketRanges that takes two 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 "<".

The following are examples cases

printBracketRanges(2, 8); // should return "2 > 3 > 4 > 5 < 6 < 7 < 8"

printBracketRanges(11, 19); // should return "11 > 12 > 13 > 14 > 15 < 16 < 17 < 18 < 19"

printBracketRanges(-2, -2); // should return "-2"

printBracketRanges(1, 10); // should return "1 > 2 > 3 > 4 > 5 - 6 < 7 < 8 < 9 < 10"

printBracketRanges(15, 16); // should return "15 - 16"

When x is greater than y, the method should throw an IllegalArgumentException.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!