Here is an example Java Program that shows how to print a Rectangle Pattern. This program is useful for school/college kids those who are learning Java programming.
Here is the complete program to print the Rectangle pattern using Java:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/** * * @author agurc */ import java.util.Scanner; public class RectanglePattern { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter the number of rows: "); int rows = sc.nextInt(); System.out.println("\nRectangle Pattern"); for (int i = 0; i < rows; i++) { for (int j = 0; j < rows; j++) { System.out.print("* "); } System.out.println(); } } |
Output:
1 2 3 4 5 6 7 |
Rectangle Pattern * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * |
This program asks for the user input to enter the number of rows for the pattern to print and then uses nested loops to print the pattern.