KnowledgeBoat Logo

Computer Applications

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

Java Conditional Stmts

4 Likes

Answer

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.

Answered By

1 Like


Related Questions