ICSE Class 10 Computer Applications
Question 14 of 43
Conditional Constructs in Java — Question 14
Back to all questions 14
Question Question 14
What will be the value of 'n' after the execution of the code given below?
int x=2, m=1, c=-1;
int n = x + c;
n = n - c + x;
System.out.println(n);n will be 4 after execution of the code.
First n = x + c is executed ⇒ n = 2 + (-1) = 1.
Next, n = n - c + x is executed.
n = n - c + x
⇒ n = 1 - (-1) + 2
⇒ n = 4
So final value of n is 4.