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           // Prompt & Take Input From User //
14           Scanner scanner = new Scanner(System.in);
15           System.out.println("Enter number of rows: ");
16           int rowInput = scanner.nextInt();
17           System.out.println("Enter number of columns: ");
18           int columnInput = scanner.nextInt();
19   
20           // Call Draw Rectangle Method //
21           drawRectangle(rowInput, columnInput);
22   
23       }
24   
25       private static void drawRectangle(int nrOfRows, int nrOfColumns) {
26           int i = 1;
27           while ( i <= nrOfRows) {
28               drawOneRow(nrOfColumns);
29               i=i+1;
30           }
31       }
32   
33       private static void drawOneRow(int nrOfColumns){
34           // Prints Out "*" For Every Column in the Row //
35           for(int i = 0; i < nrOfColumns; i++){
36               System.out.print("*");
37           }
38           // Returns Cursor After Row Completion //
39           System.out.print("\n");
40       }
41   }