ICSE Class 9 Computer Applications Question 17 of 21

Operators in Java — Question 17

Back to all questions
17
Question

Question 17

What is the difference between the following two statements? Explain the results.
x -= 5;
x =- 5;

Answer

The first statement, x -= 5; subtracts 5 from x and assigns the result back to x. It is equivalent to x = x - 5;
The second statement, x =- 5; assigns the value of -5 to x.