Sail E0 Webinar
Question

With x = 0, which of the following are legal lines of Java code for changing the value of x to 1?

 1. x++;

 2. x = x + 1;

 3. x += 1;

 4. x =+ 1;

Options:
A .  1, 2 & 3
B .  1 & 4
C .  1, 2, 3 & 4
D .  3 & 2
Answer: Option D


Operator ++ increases value of variable by 1. x = x + 1 can also be written in shorthand form as x += 1. Also x =+ 1 will set the value of x to 1.



Was this answer helpful ?
Next Question

Submit Solution

Your email address will not be published. Required fields are marked *

Latest Videos

Latest Test Papers