KnowledgeBoat Logo
|

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

  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

Answered By

57 Likes


Related Questions