ICSE Class 10 Computer Applications Question 26 of 30

Solved Sample Paper 2 — Question 26

Back to all questions
26
Question

Question 2(vi)

Rewrite the following program segment using while instead of for loop.

int f = 1, i; 
for(i = 1; i <= 5 ; i++)
{
    f *= i; 
    System.out.println(f);
}
Answer
int f = 1; i = 1;
while(i <= 5)   {
    f *= i;
    System.out.println(f);
    i++;
}