TextRectangles.java
1    /* 
2     *Asks the user for a number of rows and columns and displays a rectangle with astericsk 
3     */
4    
5    package npw;
6    
7    import java.util.Scanner;
8    
9    public class TextRectangles {
10       private static void drawOneRow(int nrOfColumns) {
11           for (int i = 0; i < nrOfColumns; i++) {
12               System.out.print("* ");
13           }
14           System.out.println("");
15       }
16   
17       private static void drawRectangle(int nrOfRows, int nrOfColumns) {
18           int i = 1;
19           while (i <= nrOfRows) {
20               drawOneRow(nrOfColumns);
21               i=i+1;
22           }
23       }
24   
25       public static void main(String[] args) {
26           Scanner scanner = new Scanner(System.in);
27           System.out.println("run: ");
28           System.out.println("number of rows?");
29           int nrOfRows = (int) scanner.nextInt();
30           System.out.println("number of columns?");
31           int nrOfColumns = scanner.nextInt();
32           drawRectangle(nrOfRows, nrOfColumns);
33   
34   
35       }
36   }
37   
38   
39