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   import static java.lang.System.*;
11   
12   public class TextRectangles {
13       public static void main(String[] args) {
14           Scanner scan = new Scanner(System.in);
15           System.out.print("number of rows? ");
16           int nrOfRows = scan.nextInt();
17           System.out.print("number of columns? ");
18           int nrOfColumns = scan.nextInt();
19           drawRectangle(nrOfRows, nrOfColumns);
20   
21       }
22   
23       private static void drawRectangle(int nrOfRows, int nrOfColumns) {
24           int i = 1;
25           while (i <= nrOfRows) {
26               drawOneRow(nrOfColumns);
27               i = i + 1;
28           }
29       }
30   
31       private static void drawOneRow(int nrOfColumns) {
32           int i = 1;
33           while (i <= nrOfColumns) {
34   
35               //Change nrOfColumns
36               // into *
37               String x = Integer.toString(nrOfColumns);
38               x = "*";
39               System.out.print(x);
40               i = i + 1;
41           }
42           System.out.println();
43       }
44   }
45