1 /* Program to draw rectangles of stars in the standard output stream. The 2 dimensions of the rectangle are read from the standard input stream. 3 */ 4 5 package npw; 6 7 import java.util.Scanner; 8 9 public class TextRectangles { 10 11 private static void drawRow(int numCols) { 12 for (int i = 0; i < numCols; i++) { 13 System.out.print("*"); 14 } 15 16 System.out.println(""); 17 } 18 19 private static void drawRectangle(int numRows, int numCols) { 20 int i = 1; 21 while ( i <= numRows) { 22 drawRow(numCols); 23 i=i+1; 24 } 25 } 26 27 public static void main(String[] args) { 28 Scanner scanner = new Scanner(System.in); 29 for (int j = 0; j<3; j = j +1) { 30 System.out.println("run: "); 31 System.out.print("number of rows? "); 32 int numRows = (int) scanner.nextInt(); 33 System.out.print("number of columns? "); 34 int numCols = scanner.nextInt(); 35 drawRectangle(numRows, numCols); 36 } 37 } 38 }