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

28th Sep 2016, 5:28 PM
Ved
Ved - avatar
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.
28th Sep 2016, 6:35 PM
Mythos
0
yea
28th Sep 2016, 5:36 PM
Azimsher Akhmedov
Azimsher Akhmedov - avatar
0
what you are trying to create is a multidimensional array.
28th Sep 2016, 6:38 PM
Eric Kershner
Eric Kershner - avatar
0
Thank you
29th Sep 2016, 2:21 AM
Ved
Ved - avatar