Write a method printRange that accepts integer parameters x and y and that print
ID: 3657392 • Letter: W
Question
Write a method printRange that accepts integer parameters x and y and that prints the sequential integers between x and y inclusive. The first half should be printed with the greater-than character (">") separating consecutive values. The second half should be printed with the less-than character ("<") separating consecutive values. The following table shows several calls and their expected output: Call Output printRange(1, 9); 1 > 2 > 3 > 4 > 5 < 6 < 7 < 8 < 9 printRange(10, 20); 10 > 11 > 12 > 13 > 14 > 15 < 16 < 17 < 18 < 19 < 20 printRange(-8, -8); -8 printRange(1, 10); 1 > 2 > 3 > 4 > 5 - 6 < 7 < 8 < 9 < 10 printRange(13, 14); 13 - 14 Notice that in the first output, 5 is in the middle with the numbers before it separated by greater-than and the numbers after it separated by less-than. In the second output, 14 is in the middle with numbers before it separated by greater-than and numbers after it separated by less-than. The third output has no separators because that range includes one number. When there are two values in the middle of the range, those two values should be separated by a dash, as shown in the last two outputs. The method should throw an IllegalArgumentException if x is greater than y. some help pleaseExplanation / Answer
public static void printRange(int i, int j) { if ((j - i) == 0) { System.out.print(i); return; } else if ((j - i) == 1) { System.out.print(i); System.out.print("-"); System.out.print(j); return; } else { if (iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.