Rectangle Star Pattern

Program to Print Rectangle Star Pattern

PRINTING PATTERN:

******
******
******
******
            

PREREQUISITE:

Basic knowledge of Java language and loops.

ALGORITHM:

1. Take the number of rows and columns as input from the user and store them in variables ('rows' and 'cols').
2. Run a loop 'rows' times to iterate through the rows (i=0 to i<rows).
3. Inside the outer loop, run another loop 'cols' times to iterate through the columns (j=0 to j<cols).
4. Print '*' for each column in the current row.
5. Move to the next line after each row has been printed.

Code in Java:

import java.util.Scanner;

public class RectanglePattern {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter the number of rows for the rectangle:");
        int rows = scanner.nextInt();  // Taking input for number of rows
        System.out.println("Enter the number of columns for the rectangle:");
        int cols = scanner.nextInt();  // Taking input for number of columns

        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cols; j++) {
                System.out.print("*");  // Printing '*' for each column in the current row
            }
            System.out.println();  // New line after each row
        }

        scanner.close();
    }
}
            

Output:

Enter the number of rows for the rectangle:
4
Enter the number of columns for the rectangle:
6
******
******
******
******