TextRectangle.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.Random;
9    import java.util.Scanner;
10   
11   import static java.lang.System.*;
12   
13   public class TextRectangle {
14       public static void main(String[] args) {
15           Scanner scanner = new Scanner(System.in);
16           System.out.println("run: ");
17           System.out.println("number of rows?");
18           int nrOfRows = scanner.nextInt();
19           System.out.println("number of columns? ");
20           int nrOfColumns = scanner.nextInt();
21           drawRectangle(nrOfRows, nrOfColumns);
22       }
23   
24       private static void drawRectangle(int nrOfRows, int nrOfColumns) {
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           int i = 0;
34           while (i < nrOfColumns) {
35               System.out.print("*");
36               i = i + 1;
37           }
38           System.out.println();
39       }
40   }
41