{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Section9Problems 5 - -2 Write that n as a parameter and...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
-2. Write a method writeSquares that takes an integer n as a parameter and t.hat wrj-tes the first n squares to System.out separated by comrnas with the odd squares in descending order followed by the even squares in ascending order. For exampl-e, the call: writeSquares (5) i shoul-d produce the f ollowing output: 25 , 9, L, 4, 1,6 The odd squares (25, 9, and 1) appear first in descending order followed b1 the even squares (4 and 16) in ascending order. Notice that corT\mas are used to separate consecutive values j-n the Iist. Your method shoul-d send its output to System.out and shoul-d not call println. For example, the following calls: writeSquares (5) i System.out.printtn O; / / to compJ-ete the line of output writeSquares (1); System.out.printlnO; // to complete the line of output writeSquares (8); System.out.printlnO; // to complete the line of output should produce exactly three Iines of output: 25, 9, L, 4, l6 1 49, 25, 9, r, 4, 16, 36, 64 You must exactl-y reproduce the format
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}