0
Can anyone help me to write a program to generate this pattern? 1 0 1 1 0 1 0 1 0 1 1 0 1 0 1
4 Answers
+ 2
String output = "";
for(int i = 1; i <= 5; i++) {
if(i % 2 == 0) {
output = "0 " + output;
} else {
output = "1 " + output;
}
System.out.println(output);
}
How it works - It loops 5 times starting at i=1. If i is even, it will append a 0 to the output, otherwise if i is odd it will append a 1 to the output. result is printed at each iteration.
0
yea
0
what you are trying to create is a multidimensional array.
0
Thank you