/* * Program to draw rectangles of stars in the standard output stream. The * dimensions of the rectangle are read from the standard input stream. */ package npw; import java.util.Scanner; import static java.lang.System.*; public class TextRectangles { public static void main(String[] args) { int i = 3 ; while(i>0) { System.out.println("run:"); int nrOfRows = Ask_For_Number("How many rows ? "); int nrOfColumns = Ask_For_Number("How many coloms ?"); drawRectangle(nrOfRows, nrOfColumns); i = i-1; } } private static int Ask_For_Number(String message) { int resval = -1; while (resval <= 0) { out.println(message); Scanner temp_scan = new Scanner(in); String temp_str = temp_scan.nextLine(); try { resval = Integer.parseInt(temp_str.trim()); } catch (NumberFormatException nfe) { out.print("Invald \nEnter neumaeric vaule \n"); } } return resval; } private static void drawRectangle(int nrOfRows, int nrOfColumns) { int i = 1; while ( i <= nrOfRows) { drawOneRow(nrOfColumns); i=i+1; } } private static void drawOneRow(int nrOfColumns) { int i = 1; while (i <= nrOfColumns){ out.print("*"); i = 1 + i; } out.println(); } }