Computer Science
Rewrite the following using for loop:
int i = 1, f = 1;
do
{
f=f*i;
i++;
}
while(i<=10);
System.out.println(f);
Java Iterative Stmts
9 Likes
Answer
int f = 1;
for (int i = 1; i <= 10; i++) {
f=f*i;
}
System.out.println(f);
Answered By
2 Likes
Related Questions
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");
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++; }
State the final value of q at the end of the following program segment after execution. Show the dry run.
for(m=2;m<=3;++m) { for(n=1;n<=m;++n) { p=m+n-1; if(p%3 == 0) q += p; else q += p+4; } }