Computer Applications
Evaluate the following expressions, when int a = 8, b = 14.
(a) b/a++
(b) --a + b-- + a
Java Operators
6 Likes
Answer
(a) b/a++
b / a++
⇒ 14 / 8 [Postfix operator first uses the value then increments it]
⇒ 1 [Integer division is performed as both a and b are int variables]
Hence, the expression evaluates to 1
(b) --a + b-- + a
--a + b-- + a
⇒ 7 + b-- + a [a = 7, Prefix operator first decrements the value then uses it]
⇒ 7 + 14 + 7 [b = 13, Postfix operator first uses the value then decrements it]
⇒ 28
Hence, the expression evaluates to 28
Answered By
3 Likes
Related Questions
Name the operators listed below.
- ?:
- &&
- <=
- ++
Find out the error(s) in the following code and underlining correct error(s).
int m = 5; n = 10; while(n >= 1) { System.out.print("m"); n--; }Write the syntax of switch statement.
What will be the output of the following program segment?
int a = 100; while(false) { if(a < 50) break; a = a - 10; } System.out.println(a);