1 /* 2 * Program to draw rectangles of stars in the standard output stream. * The 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 public static void main(String[] args) { 12 13 Scanner scanner = new Scanner(System.in); 14 15 System.out.print("number of rows? "); 16 int nrOfRows = scanner.nextInt(); 17 18 System.out.print("number of columns? "); 19 int nrOfColumns = scanner.nextInt(); 20 21 drawRectangle(nrOfRows, nrOfColumns); 22 } 23 24 private static void drawRectangle(int nrOfRows, int nrOfColumns) { 25 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 35 int i = 1; 36 while ( i <= nrOfColumns) { 37 System.out.print("*"); 38 i = i + 1; 39 } 40 System.out.println(); 41 } 42 }