logo Practice-It logo

BJP3 Exercise 12.6: writeSquares

Language/Type: Java recursion recursive programming
Author: Whitaker Brand (on 2013/04/01)

Write a method writeSquares that accepts an integer parameter n and prints the first n squares separated by commas, with the odd squares in descending order followed by the even squares in ascending order. The following table shows several calls to the method and their expected output:

Call Valued Returned
writeSquares(5); 25, 9, 1, 4, 16
writeSquares(1); 1
writeSquares(8); 49, 25, 9, 1, 4, 16, 36, 64

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

Type your solution here:

This is a method problem. Write a Java method as described. Do not write a complete program or class; just the method(s) above.

You must log in before you can solve this problem.

Log In

If you do not understand how to solve a problem or why your solution doesn't work, please contact your TA or instructor.
If something seems wrong with the site (errors, slow performance, incorrect problems/tests, etc.), please

Is there a problem? Contact a site administrator.