Write a program to display the following pattern :
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
display a program of java in full details
Answers
Skip to main content
Brainly.in
What is your question?
1
swarnimprabhat4d
ASK YOUR QUESTION
Secondary School Math 5+3 pts
Splitting the middle term of : 2x^2+5/3x-2
by Kotayaswanth2896 Yesterday
Ask for details Follow Report
Answers
You are so Brainly right now
swarnimprabhat4d
We're happy to have you!
KEEP GOING
Your influence
1
Answering Streak
Your Streak is on! Answer another question tomorrow and keep it going.
Fun fact
An apple, potato, and onion all taste the same if you eat them with your nose plugged
1
2
2
Get +4
bonus
2
Last 7 days
Overall
Your stats from the last 7 days compared with the previous 7 days
0/25
2d : 00h
START
You may attempt only one challenge at a time.
Answer 5 Science questions in 48 hours to collect 50 points
0/5
2d : 00h
START
You may attempt only one challenge at a time.
Answer 10 Science questions in 48 hours to collect 100 points
0/10
2d : 00h
Java Programs to print pattern 1 10 101 1010 10101
The outer loop counter i ranges from 1 to n. i is used to keep track of line number. Line i contains i numbers. So, the inner loop counter j ranges from 1 to i. If j is odd, we print 1, else we print 0.
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 (j % 2 == 1) {
System.out.print("1 ");
} else {
System.out.print("0 ");
}
}
System.out.println();
}
}
}
Enter n: 5
1
1 0
1 0 1
1 0 1 0
1 0 1 0 1