Computer Applications
Give the output of the following method:
public static void main (String [] args){
int a = 5;
a++;
System.out.println(a);
a -= (a--) - (--a);
System.out.println(a);}
Java
Java Operators
ICSE 2014
110 Likes
Answer
6
4
Working
- a++ increments value of a by 1 so a becomes 6.
- a -= (a--) - (--a)
⇒ a = a - ((a--) - (--a))
⇒ a = 6 - (6 - 4)
⇒ a = 6 - 2
⇒ a = 4
Answered By
57 Likes
Related Questions
Rewrite the following program segment using logical operators:
if(x > 5) if(x > y) System.out.println(x + y);Evaluate the expression when x is 4:
x += x++ * ++x % 2;
Identify the operator that gets the highest precedence while evaluating the given expression:
a + b % c * d - e
- +
- %
- -
- *
Write Java expression for: