Variables and loops

posted by: Ms. Martin 19 September 2010 No Comment

These problems are designed to give you practice breaking down repetitive problems into steps.  In reality, it’s not particularly useful to print out sequences of numbers but this kind of thinking is critical for solving larger problems!

Create a class and call it something descriptive.  Write and call methods that do the following (don’t worry about any extra blank newlines):

  1. Print out the sequence 97, 94, 91, 88, 85, 82 using a loop
  2. Print out all odd numbers between 1 and 21 (inclusive) using a loop
  3. Print out the following pattern:
    1
    22
    333
    4444
    55555
  4. Print out the following pattern (each line is 40 characters wide):
    ----------------------------------------
    _-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-_-^-
    1122334455667788990011223344556677889900
    ----------------------------------------
  5. Print out the following pattern:
    -----1-----
    ----333----
    ---55555---
    --7777777--
1 Star2 Stars3 Stars4 Stars5 Stars (13 votes, average: 2.92 out of 5)
Loading ... Loading ...

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>