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

Info icon This 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
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 ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern