Computer Applications
What will be the output of the following code?
int x = 9;
x -= 2 * --x / x++ % 3;
System.out.println("x = " + x);
Java Operators
2 Likes
Answer
x = 7
Reason — The given expression is evaluated as follows:
Initial value: x = 9
x -= 2 * --x / x++ % 3
x = x - (2 * --x / x++ % 3) [x=9]
x = 9 - (2 * 8 / 8 % 3) [x=9]
x = 9 - (16 / 8 % 3)
x = 9 - (2 % 3)
x = 9 - 2
x = 7
Answered By
2 Likes
Related Questions
Evaluate the given expression when the value of a=2 and b=3
b*=a++ - ++b + ++a; System.out.println("a= "+a); System.out.println("b= "+b);A student executes the following code to increase the value of a variable ‘x’ by 2.
He has written the following statement, which is incorrect.
x = +2;What will be the correct statement?
A. x +=2;
B. x =2;
C. x = x +2;- Only A
- Only C
- All the three
- Both A and C
Write a Java program to obtain principal amount, rate of interest and time from user and compute simple interest.