QuesAns Print Page – CSKC
Sign In

Search

siteicon
Q&A ICSE2014-03E #7403

Question:

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

Answer:

6
4

Notes:

a++ increments a from 5 to 6. The first print statement prints the value of a which is 6.
a -= (a–) – (–a);
is equivalent to
a = a – ( (a–) – (–a) )
a = 6 – ( 6 – 4 )
a = 6 – 2
a = 4