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           Scanner input = new Scanner(System.in);
13           System.out.print("Number of rows? ");
14           int nrOfRows = input.nextInt();
15           System.out.print("Number of columns? ");
16           int nrOfColumns = input.nextInt();
17           drawRectangle(nrOfRows, nrOfColumns);
18       }
19   
20       private static void drawRectangle(int nrOfRows, int nrOfColumns) {
21           int i = 1;
22           while ( i <= nrOfRows) {
23               drawOneRow(nrOfColumns);
24               i = i + 1;
25           }
26       }
27   
28       private static void drawOneRow(int nrOfColumns) {
29           int x = 0;
30               while (x < nrOfColumns) {
31                   System.out.print("*");
32                   x = x + 1;
33               }
34   
35               if (x == nrOfColumns) {
36               System.out.print("\n");
37           }
38   
39       }
40   }
41   
42   
43