Computer Science

Rewrite the following using for loop:

a=1;
while(a<=5)
{b = 1;
while(b<=a)
{ 
System.out.print(b);
b++;
} 
System.out.println();
a++;
}

Java Iterative Stmts

5 Likes

Answer

for (a = 1; a <= 5; a++) {
    for (b = 1; b <= a; b++) {
        System.out.print(b);
    }
    System.out.println();
}

Answered By

2 Likes


Related Questions