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 kmart = new Scanner(System.in);
13           System.out.println("number of rows? ");
14           int rows = kmart.nextInt();
15           System.out.println("number of columns? ");
16           int columns = kmart.nextInt();
17   
18           drawRectangle(rows, columns);
19   
20       }
21   
22       private static void drawRectangle(int nrOfRows, int nrOfColumns) {
23           int i = 1;
24           while ( i <= nrOfRows) {
25               drawOneRow(nrOfColumns);
26               i=i+1;
27           }
28       }
29       private static void drawOneRow(int nrOfColumns)
30       {
31           for(int k = 0; k < nrOfColumns; k++)
32           {
33               System.out.print("*");
34           }
35           System.out.println("");
36       }
37   }