Slip No 9 Q A

Q.Write a java Program to display following pattern: [15 M]
1
0 1
0 1 0
1 0 1 0

public class BinaryPattern {
    public static void main(String[] args) {

        int[][] pattern = {
            {1},
            {0,1},
            {0,1,0},
            {1,0,1,0}
        };

        // Display pattern
        for(int i = 0; i < pattern.length; i++) {
            for(int j = 0; j < pattern[i].length; j++) {
                System.out.print(pattern[i][j] + " ");
            }
            System.out.println();
        }
    }
}
Spread the love

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top