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
Rewrite the following statement using if-else:
s = (a + b < c || a + c <= b || b + c <= a) ? "Triangle is not possible": "Triangle is possible";Rewrite the following statement using if-else:
c = (x >= 'A' && x <= 'Z') ? "Upper Case Letter": "Lower Case Letter";Rewrite the following for loop by using while and do-while loops:
int p = 20; for(k=p;k>=0;k-=2) { s += k; } System.out.println("Sum="+s);Rewrite the following for loop by using while and do-while loops:
int a=37, b, c=0; for(b=1;b<=a;b++) { if (a % b == 0) c = c + 1; } if(c == 2) System.out.println(a + " is a prime number"); else System.out.println(a + " is not a prime number");