How can I stack up the number patterns with while loop in java? -
dear professionals! i'm super beginner of programming java. i'm learning basic stuff in school. while i'm doing homework, i'm stuck in 1 problem.
the question using nested loops make stack-up number pattern:
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5 1 2 3 4 5 6 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9 10
i can use while loop (because haven't learned or loops yet), , outer loop body should execute 10 times. can use print , println making pattern.
i tried many different methods while loop, can't figure out.
please, please give me hint.
this code i'm working on far:
class c4h8 { public static void main(string[] args) { int i, j; = 1; while(i <= 10) { j = 1; while (j <= 10) { system.out.print(j); j++; } system.out.println(); i++; } } }
but displays:
12345678910 12345678910 12345678910 12345678910 12345678910 12345678910 12345678910 12345678910 12345678910 12345678910
my question may silly one, i'm struggling because mentioned, i'm super beginner.. please me, can learn , move on!
thank much!
use following: need limit variable j
variable i
achieve output
class c4h8 { public static void main(string[] args) { int i, j; = 1; while(i <= 10) { j = 1; while (j <= i) // limit variable j { system.out.print(j+" "); j++; } system.out.println(); i++; } } }
Comments
Post a Comment