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 //Creating the scanner input to let user input rows and columns 12 public static void main(String[] args) { 13 Scanner scanner = new Scanner(System.in); 14 System.out.println("Enter number of rows: "); 15 int nrOfRows = (int) scanner.nextInt(); 16 System.out.println("Enter number of columns: "); 17 int nrOfColumns = scanner.nextInt(); 18 drawRectangle(nrOfRows, nrOfColumns); 19 } 20 21 //Creating the rectangle 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 public static void drawOneRow(int nrOfColumns) { 31 for (int i = 0; i < nrOfColumns; i++) { 32 System.out.print("*"); 33 } 34 System.out.println(""); 35 } 36 }