Computer Science, asked by jhumab205, 1 year ago

HOW TO PRINT THE PATTERN IN JAVA
01
010
01010
010101

Answers

Answered by meghana68852
3
import java.util.Scanner;

 

public class Pattern {

 

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);

        System.out.print("Enter n: ");

        int n = scanner.nextInt();

        for (int i = 1; i <= n; i++) {

            for (int j = 1; j <= i; j++) {

                if ((i + j) % 2 == 0) {

                    System.out.print("1 ");

                } else {

                    System.out.print("0 ");

                }

            }

            System.out.println();

        }

    }

}

Sample Output

1

2

3

4

5

6

7

8

Enter n: 7

1

0 1

1 0 1

0 1 0 1

1 0 1 0 1

0 1 0 1 0 1

1 0 1 0 1 0 1

 


meghana68852: plz mark to branliest
charita24: ya mark her
charita24: becoz my answer is wrong
Answered by charita24
2
i marked with blue crayon there u write string args [ ]

Attachments:
Similar questions