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:
/**
*
* @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:
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.