Basic Square 1 Pattern

Program to Print Basic Square 1 Pattern

PRINTING PATTERN:

1111
1111
1111
1111
            

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 ('n' for rows and 'm' for columns).
2. Run a loop 'n' times to iterate through the rows.
3. For each row, run another loop 'm' times to print '1'.
4. Move to the next line after each row has been printed.

Code in Java:

import java.util.Scanner;

public class BasicSquarePattern {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("Enter the number of rows and columns for the square pattern:");
        int n = scanner.nextInt();  // Number of rows
        int m = scanner.nextInt();  // Number of columns

        // Loop to print the square pattern
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                System.out.print("1");  // Printing '1'
            }
            System.out.println();  // New line after each row
        }

        scanner.close();
    }
}
            

Output:

Enter the number of rows and columns for the square pattern:
4 4
1111
1111
1111
1111