filmov
tv
Java Practice It | Exercise 12.6: writeSquares | recursion, recursive training
Показать описание
More practice its:
Problem:
Question:
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.
Problem:
Question:
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.