int k=1,i=2;
while(++i<6)
k*=i;
System.out.println(k);
Q:How many times will the loop be executed ?
(It is a java based question)
saurez:
is it a question of C++
Answers
Answered by
52
The given loop will be executed three times .
For the first time in the while loop , the value of i is 3 due to use of increment operator and it's value is less than 6 , the loop will work . The value k = k×i will be printed , equal to 3.
The next time the value of i is incremented by one and is equal to 4 and is less than 6. Thus , the while loop will be executed . This time the value of k = k×i is printed , equal to 12.
The while loop will work for the last time for I = 5 and the value printed will be 60.
After i= 5 the while loop will not work because the condition of the loop is not satisfied .
Answered by
9
Answer:
3 times
Explanation:
1st loop, k=3
2nd loop, k=12
3rd loop, k=60
Similar questions