Skip to main content
Lesson 10 - for, do-while, Nested Loops
ZIPPDF (letter)
Lesson MenuPreviousNext
  
L.A.10.1 - Pictures page 8 of 10

Assignment:

  1. Write a method that takes in, through its parameters, the number of rows and columns to print in a multiplication table.

  2. There must be a margin of row and column headings for the table.

  3. The answer columns should be separated by a field-width of 5 columns.

  4. A blank line should be inserted between the column heading and the first row of the table.

  5. A precondition of the procedure is that the value of the row or column will be from 1..12.

  6. Sample run output for printTable(4,6):


             1     2     3     4     5     6
    
       1     1     2     3     4     5     6
       2     2     4     6     8    10    12
       3     3     6     9    12    15    18
       4     4     8    12    16    20    24
    __________________________________________

  7. Write another method to print the following pyramid pattern of stars. If the number of lines = 5, then:

        *
       ***
      *****
     *******
    *********
  8. Such a method should take in, through its parameter list, the number of lines to print. The precondition of this method, lines <= 30.


Instructions:

  1. The main method will consist of only 4 method calls separated by readLine() calls.

    public class PicturesTest
    {
      public static void main (String[] args)
      {
        Pictures pic = new Pictures();
        ConsoleIO keyboard = new ConsoleIO();
        String get;
    
        pic.printTable(4,6);
        get = keyboard.readLine(); // freezes the output screen to see the picture
        pic.printTable(11,12);
        get = keyboard.readLine();
        pic.pyramid(10);
        get = keyboard.readLine();
        pic.pyramid(25);
        get = keyboard.readLine();
      }
    }
  2. The readLine() between the four method calls will hold the picture until a return key is entered.

  3. Your source code must include a pseudocode version of each method. Write your pseudocode above your actual code as documentation. Please follow the process and develop your pseudocode first, then translate it to code. You need to practice this system of problem solving on relatively easy problems so that you can apply it to more difficult problems.


Lesson MenuPreviousNext
Contact
 ©ICT 2003, All Rights Reserved.