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

Views 10

Answer:


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

Related Articles:

This section is dedicated exclusively to Questions & Answers. For an in-depth exploration of Java Programming Language, click the links and dive deeper into this subject.

Join Our telegram group to ask Questions

Click below button to join our groups.