Practice-It! logo

Exercise 12.2: writeNums

Added by: Whitaker Brand on 2010/05/16
Keywords: recursion

Write a method writeNums that accepts an integer parameter n and prints the first n integers starting with 1 in sequential order, separated by commas. For example, the following calls produce the following output:

Call Output
writeNums(5); 1, 2, 3, 4, 5
writeNums(12); 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12

Your method should throw an IllegalArgumentException if passed a value less than 1. Note that the output does not advance to the next line.

You must log in before you can solve this problem.

user
Log In


indent Re-indent

If you do not understand how to solve a problem or why your solution code doesn't work, please contact your TA or instructor.

If something seems wrong with the Practice-It system itself (errors, slow performance, incorrect problem descriptions/tests, etc.), please contact us.


Is there a problem?
Contact a Practice-It administrator.