Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
762 B
6
Indexable
Never
import java.util.Scanner;

public class PatternPrinting {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("Enter the number of rows (M): ");
        int m = scanner.nextInt();
        System.out.print("Enter the number of columns (N): ");
        int n = scanner.nextInt();
        
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                if (i == j || i == m - j - 1) {
                    System.out.print("#");
                } else if (i % 2 == 0) {
                    System.out.print("#");
                } else {
                    System.out.print("$");
                }
            }
            System.out.println();
        }
    }
}