logo CodeStepByStep logo

printRange

Write a method named printRange that accepts two integers as arguments and prints the sequence of numbers between the two arguments, separated by spaces. Print an increasing sequence if the first argument is smaller than the second; otherwise, print a decreasing sequence. If the two numbers are the same, that number should be printed by itself. For the following sample calls to printRange, the output produced should be the following:

Call Output
printRange(2, 7); 2 3 4 5 6 7
printRange(19, 11); 19 18 17 16 15 14 13 12 11
printRange(5, 5); 5
Method: Write a Java method as described, not a complete program or class.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.