java - Nested for loop for a triangle -


i'm beginner in java & need answer. have been trying create triangle in sequence:

1 21 321 4321 54321 

even though syntax correct, have been going through logical errors non-terminating loops.

this program i'm trying fix:

for(i=1;i>=1;i++)     {         for(j=i;j<=i;j=j-1)         {             system.out.print(j);                 }         system.out.println();      } 

help appreciated this.

you non-terminating loop because of

for(i=1;i>=1;i++) 

the code means, want loop body if i greater or equal 1 (i>=1), , i value incremented 1 (i++) each loop, have value greater 1 , condition correct loop code. must correct loop statement.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -