Computer Science

Rewrite the following for loop by using while and do-while loops:

for(i=1,j=1;i<=10;i++,j++)
{
    System.out.println(i*j);
}

Java Iterative Stmts

45 Likes

Answer

// Using while loop
int i = 1, j = 1;
while (i <= 10) {
    System.out.println(i*j);
    i++;
    j++;
}
// Using do-while loop
int i = 1, j = 1;
do {
    System.out.println(i*j);
    i++;
    j++;
} while (i <= 10);

Answered By

19 Likes


Related Questions