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
Post a Comment