Computer Science, asked by vanshika1393, 1 year ago

give the output of the following snippets based on nested loops
int i,j;
for(i=0;i<4;i++)
{
for(j=i;j>=0;j--)
System.out.print(j);
System.out.println();
}

Answers

Answered by Anonymous
16

OUTPUT :


0

1 0

2 1 0

3 2 1 0



LOGIC :

The j-loop is printing the pattern.

The pattern will depend on the value of the j in the loop.

The initial j value = i value .

The j-loop starts from 0 .

0

Then in the next iteration it starts from 1 and goes till 0.

1 0

Then in the next step , j starts from i which is 2

Like this it gets printed .

2 1 0

Then again from 3

3 2 1 0


vanshika1393: I tried this program in computer. computer gives 0 10 210 3210 as a output
Anonymous: Ohh maybe then ur code is wrong ... wait
Anonymous: hmm it will like that only sorry ...
Answered by prakhargurunani
6

0

10

210

310

First 'i' undergoes increments

Then it undergoes decrements.


somaneogi9: But the last one will be 3210
Similar questions