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);10111213

🧐 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

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 code snippet?int i = 0;while (i < 5) {    if (i == 3)        break;    System.out.print(i + " ");    i++;}

What will be the output of the program?public class Sample{    public static void main(String [] args)    {        int i = 10;        do while ( i < 10 )        System.out.print("The value of i is " + i);        while ( i > 10 ) ;    }}Select one:a.The value of i is 10b.No output is produced.c.Compilation errord.The value of i is 10 The value of i is 10

What is the output of the programme below?public static void main(String[] args) {     int x = 0;     while (x < 10) {          if (x & 2 == 0) {               System.out.print(x + “ “);          }          x++;     }}

What will be the output of the following program?while i < 20: print(i) i += 1

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.