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           //create scanner
13           Scanner scanner = new Scanner(System.in);
14           //collect rows and columns
15           System.out.println("Please enter the number of rows");
16           int nrOfRows = scanner.nextInt();
17           System.out.println("Please enter the number of columns");
18           int nrOfColumns = scanner.nextInt();
19           //draw the rectangle
20           drawRectangle(nrOfRows, nrOfColumns);
21       }
22   
23       private static void drawRectangle(int nrOfRows, int nrOfColumns) {
24   
25           int i = 1;
26           while ( i <= nrOfRows) {
27               drawOneRow(nrOfColumns);
28               i=i+1;
29           }
30       }
31   
32       private static void drawOneRow(int nrOfColumns) {
33   
34           int k = 1;
35           while (k <= nrOfColumns) {
36               System.out.print("*");
37               k = k+1;
38           }
39           System.out.println(" ");
40       }
41   }
42