πŸ“Š JAVA
Q. What is the value of k after the following code fragment?~~~int k = 0;~~~int n = 12~~~while (k < n)~~~{~~~k = k + 1;~~~}
  • (A) 0.
  • (B) 11.
  • (C) 12.
  • (D) 10.
πŸ’¬ Discuss
βœ… Correct Answer: (C) 12.

Explanation: You might wonder that how this value will be 12. Since k is initialised with 0 and n with 12.

Now while loop checks whether value of k is smaller than n or not. So this condition will be true unless te value of k becomes 11.

Now the value of k is 11 and the condition is true to while loop will be executed and now k will become 12.

So the final value of k will be 12.

Explanation by: Monu Rathod
You might wonder that how this value will be 12. Since k is initialised with 0 and n with 12.

Now while loop checks whether value of k is smaller than n or not. So this condition will be true unless te value of k becomes 11.

Now the value of k is 11 and the condition is true to while loop will be executed and now k will become 12.

So the final value of k will be 12.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
200
Total Visits
πŸ“½οΈ
2 y ago
Published
πŸŽ–οΈ
Mr. Dubey
Publisher
πŸ“ˆ
94%
Success Rate