Computer Applications
What is the difference between the following two statements in terms of execution? Explain the results.
x -= 5;
x =- 5;
Java Operators
42 Likes
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.
Answered By
27 Likes
Related Questions
What is concatenation? On which data type is concatenation performed?
Determine the output of the following program.
public class PredictOutput1 { public static void main(String args[]) { int a = 4, b = 2, c = 3; System.out.println("Output 1: " + (a = b * c)); System.out.println("Output 2: " + (a = (b * c))); } }
Rewrite the following statements without using shorthand operators.
a. p /= q
b. p -= 1
c. p *= q + r
d. p -= q - rDetermine the output of the following program.
public class Test { public static void main(String[] args) { int a = 1, b = 2; System.out.println("Output1: " + a + b); System.out.println("Output2: " + (a + b)); } }