TextRectangles.java
1    
2        /* 
3         * Program to draw rectangles of stars in the standard output stream. The 
4         * dimensions of the rectangle are read from the standard input stream. 
5         */
6    
7    package npw;
8    
9    import java.util.Scanner;
10   
11       public class TextRectangles {
12           public static void main(String[] args) {
13               Scanner scanner = new Scanner(System.in);
14               System.out.print("Enter the number of rows: ");
15               int nrOfRows = scanner.nextInt();
16               System.out.print("Enter the number of columns: ");
17               int nrOfColumns = scanner.nextInt();
18               drawRectangle(nrOfRows, nrOfColumns);
19           }
20   
21           private static void drawRectangle(int nrOfRows, int nrOfColumns) {
22               int i = 1;
23   
24               while (i <= nrOfRows) {
25                   drawOneRow(nrOfColumns);
26                   i = i + 1;
27   
28               }
29   
30           }
31   
32           private static void drawOneRow(int nrOfColumns) {
33               int j = 1;
34   
35               while (j <= nrOfColumns) {
36   
37                   System.out.print("*");
38                   j++;
39   
40   
41               }
42               System.out.println("");
43           }
44       }
45