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   
13           Scanner scanner = new Scanner(System.in);
14           System.out.println("Number of rows?");
15           int nrOfRows = scanner.nextInt();
16           System.out.println("Number of columns?");
17           int nrOfColumns = scanner.nextInt();
18           drawRectangle(nrOfRows, nrOfColumns);
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   
30       private static void drawOneRow(int nrOfColumns) {
31           int i = 1;
32           while ( i <= nrOfColumns) {
33               System.out.print("*");
34               i = i +1;
35           }
36           System.out.println();
37           }
38       }