Write a Program that will ask the user to input the
length and width of the rectangle pattern using
“*”.
Enter the length of rectangular pattern: 5
Enter the width of the rectangular pattern: 4
Output:
****
****
****
****
****
Hint: Use Do-while inside a Do-while
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the length of rectangular pattern: ");
int length = in.nextInt();
System.out.print("Enter the width of the rectangular pattern: ");
int width = in.nextInt();
do {
int widthT = width;
do {
System.out.print("*");
} while (--widthT > 0);
System.out.println();
} while (--length > 0);
}
}
Comments
Thank you.
Leave a comment