English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

OK, this is for someone who knows JAVA, so others buzz off !
How exactly do I devise a code to diaplay the following pattern ?
0
0 1
1 0 1
0 1 0 1

2006-07-30 02:50:45 · 7 answers · asked by Anonymous in Computers & Internet Programming & Design

(SORRY : That's 'display')

2006-07-30 02:55:47 · update #1

7 answers

So im starting with 0 and doing n iterations... so if I want 4 lines I would put iterations=3, since the sequence will always start as 0.

String sequence = "0";
int iterations = 3; //number of lines you want at the end

System.out.println( sequence ); //sequence always start with 0
for( int n = 0; n < iterations; n++ )
{
if( n == 0 )
sequence += " 1";
else
sequence = n % 2 + " " + sequence;

System.out.println( sequence );
}

this is an O(n) algorithm.. might not look too nice but it does the work an fast.

2006-07-30 03:32:31 · answer #1 · answered by DjoeX 2 · 0 0

int i=0,j=0,k;
for(i=0;i {
for(j=0;j<=i;j++)
{
k=j%2;
System.out.printf("%d",k);
}
System.out.printf("\n");
}

// Place this in you main method of the object.

2006-07-30 03:01:41 · answer #2 · answered by xlord_vader 3 · 0 0

you can do it in one loop and simply add the opposite of the (0,1) that was added in the last iteration

2006-07-30 02:55:07 · answer #3 · answered by Ivanhoe Fats 6 · 0 0

hint: u will have to use 2 'for' loops.

2006-07-30 02:53:01 · answer #4 · answered by nice01guyin 3 · 0 0

Buuuzzzzzzzzzzzzzzzzzzzzzzzzzzz!!!!!!!!!!!!!!!!

2006-07-30 02:52:56 · answer #5 · answered by Texas Cowboy 7 · 0 0

ok ----i,m not logical
good luck mr logical

2006-07-30 02:54:37 · answer #6 · answered by hanifrng 3 · 0 0

10101
010101
1010101
01010101
101010101

2006-07-30 02:54:07 · answer #7 · answered by Japan_is_home 5 · 0 0

fedest.com, questions and answers