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