Home / Questions / 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);}
Explanatory Question

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);} 

👁 100 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation


6
4
Explanation
  1. a++ increments value of a by 1 so a becomes 6.
  2. a -= (a--) - (--a)
    ⇒ a = a - ((a--) - (--a))
    ⇒ a = 6 - (6 - 4)
    ⇒ a = 6 - 2
    ⇒ a = 4