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    package npw;
6    
7    import java.util.Scanner;
8    
9    public class TextRectangles {
10       public static void main(String[] args){
11           Scanner scanner = new Scanner(System.in);
12           System.out.print("number of rows? ");
13           int nrOfRows = scanner.nextInt();
14           System.out.print("number of columns? ");
15           int nrOfColumns = scanner.nextInt();
16           drawRectangle(nrOfRows, nrOfColumns);
17       }
18   
19       private static void drawRectangle(int nrOfRows, int nrOfColoums) {
20           int i = 1;
21           while (i <= nrOfRows) {
22               drawOneRow(nrOfColoums);
23               i=i+1;
24           }
25       }
26   
27       private static void drawOneRow(int nrOfColoums) {
28           String star = "*";
29           int j = 1;
30           while (j <= nrOfColoums){
31               System.out.print(star);
32               j=j+1;
33           }
34           System.out.println();
35       }
36   
37   }
38