/home/kchan2/NetBeansProjects/CS1/src/npw/TextRectangles.java
 1 /*
 2  * Program to draw rectangles with stars in the standard output stream. The 
 3  * dimensions of the rectangles are read from the standard input stream.
 4  */
 5 
 6 package npw;
 7 
 8 import java.util.Scanner;
 9 
10 /**
11  *
12  * @author kchan2
13  */
14 public class TextRectangles {
15 
16     /**
17      * @param args the command line arguments
18      */
19     public static void main(String[] args) {
20         System.out.print("number of rows? ");
21         Scanner scanner = new Scanner(System.in);
22         int nrOfRows = scanner.nextInt();
23         System.out.print("number of columns? ");
24         int nrOfColumns = scanner.nextInt();
25         drawRectangle(nrOfRows,nrOfColumns);
26     }
27 
28     private static void drawRectangle(int nrOfRows, int nrOfColumns) {
29         int i = 1;
30         while (i <= nrOfRows){
31             drawOneRow(nrOfColumns);
32             i = i + 1 ;
33         }
34     }
35 
36     private static void drawOneRow(int nrOfColumns) {
37         int j = 1;
38         while (j <= nrOfColumns) {
39             System.out.print("*");
40             j = j + 1 ;
41         }
42         System.out.println();
43     }
44     
45 }
46