Home » JAVA Programming » Basic Operators » Question
  1. 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;
    1. 1, 2, 3 & 4
    2. 3 & 2
    3. 1 & 4
    4. 1, 2 & 3
    5. None of these
Correct Option: A

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.



Your comments will be displayed only after manual approval.