What will the result of num1 variable after execution of the following statements? int j = 1, num1 = 4; while (++j <= 10) { num1++; } ans. 14 15 13 11
Question
What will the result of num1 variable after execution of the following statements? int j = 1, num1 = 4; while (++j <= 10) { num1++; }
ans. 14
15
13
11
Solution
The initial value of num1 is 4. The while loop will increment j from 2 to 10 (inclusive), which is 9 times. Therefore, num1 will also be incremented 9 times. So, the final value of num1 will be 4 + 9 = 13. So, the correct answer is 13.
Similar Questions
What will the result of num variable after execution of the following statements?int num = 58;num % = 11;ans.
What will be the result?1. int i = 10;2. while(i++ <= 10){3. i++;4. }5. System.out.print(i);10111213
What is wrong with the following code segment if the numbers from 1 to 10 are meant to be output? int num = 1; while (num > 0){ num = num + 1; System.out.println(num); }a.)Nothing is printed in the while loop.b.)The variable should be initialized to 0.c.)The while expression should be evaluated with <.d.)The while loop is an infinite loop and will produce an error.
What will be the output of the following code?int num = 2;int count=0;while(num!= 0){if ( num & 01)count ++;num >>=1;}cout<< count;return 0;
What output is displayed when the following code is run?int num1 = 11;int num2 = 18;int num3 = 15;int num4 = 0;if (num1 > num3) { num4 = 4;} else { if (num2 > num3) { num4 = 5; }}System.out.println(num4);50424
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.