Knowee
Questions
Features
Study Tools

What will be the result?1. int i = 10;2. while(i++ <= 10){3. i++;4. }5. System.out.print(i);10111213

Question

What will be the result?

  1. int i = 10;
  2. while(i++ <= 10){
  3.    `i++;`
    
  4. }
  5. System.out.print(i);

10 11 12 13

🧐 Not the exact question you are looking for?Go ask a question

Solution

The result will be 13. Here's the step by step explanation:

  1. An integer i is initialized with a value of 10.
  2. The while loop condition checks if i incremented by 1 (i++) is less than or equal to 10. Since i is initially 10, i++ in the condition will increment i to 11 but return the original value (10) for the comparison. So, the condition is true and the loop will execute.
  3. Inside the loop, i is incremented again by 1, making i now 12.
  4. The loop condition is checked again. i++ in the condition will increment i to 13 but return the original value (12) for the comparison. Since 12 is greater than 10, the condition is false and the loop will not execute again.
  5. The value of i (which is now 13) is printed.

This problem has been solved

Similar Questions

How does a WHILE loop start?{$a->questionintifier} Yanıta.while (i <= 10; i++)b.while (i <= 10)c.while i = 1 to 10d.while (i=0; i <= 10; i++)

What is the output of the following code snippet?int i = 0;do {    if (i == 3)        continue;    System.out.print(i + " ");    i++;} while (i < 5);

What will be the output of the following code?          int i = 1;while(i<10){  if (i / 2 == 2)     cout << i << “ ”;i++;}

What is the output of the following piece of code?int i;i = 10;while (i < 20){ printf("%d", i % 2); i++;}

What will the result of num1 variable after execution of the following statements? int j = 1, num1 = 4; while (++j <= 10) { num1++; } ans.

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.