In: Computer Science
in.java
Write a program that reads an integer from the user and prints a rectangle of starts of width 5 3 and height N.
Sample run 1: Enter N: 5 *** *** *** *** *** Bye Sample run 2: Enter N: 8 *** *** *** *** *** *** *** *** Bye Sample run 3: Enter N: 2 *** *** Bye Sample run 4: Enter N: -2 Bye
/* Please read all the comments and see the output*/
import java.io.BufferedReader; // For BufferedReader Class to read data
import java.io.InputStreamReader; // For inputStream Reader for keyboard input
class Test {
public static void main(String arg[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter N: "); // Ask user input
int height = Integer.parseInt(br.readLine()); // Convert input to integer
for(int h=1;h<=height;h++) //Print *** for given height
System.out.println("***");
System.out.println("Bye"); // Print Bye at the end
}
}
/* This is output */