TextRectangles.java
1    /* 
2     * A program that will (1) accept, from the standard input stream, data corresponding to the number of rows and number of columns in a rectangle made up of stars, and (2) print, to the standard output stream, the rectangle of stars. 
3     * Program that draws rectangles of stars in the standard output stream, where the dimensions of the rectangle are read from the standard output stream. 
4     */
5    
6    package npw;
7    
8    import java.util.Scanner;
9    
10   public class TextRectangles {
11   
12       public static void main(String[] args) {
13       Scanner sc = new Scanner(System.in);
14       System.out.println("number of rows? ");
15       int nrOfRows = sc.nextInt();
16       System.out.println("number of columns? ");
17       int nrOfColumns = sc.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   
31       private static void drawOneRow(int nrOfColumns) {
32           int x = 1;
33           while ( x <= nrOfColumns) {
34               System.out.print("*");
35               x=x+1;
36   
37           } System.out.println();
38       }
39   }