Initially, Jim had x+y+2 candies.
He gave 1 candy to each of his x+y classmates.
⇒ He distributed x+y candies among his classmates.
∵ Number of candies is a like term, it can be added or subtracted.
∴ Number of candies left with him
=(x+y+2)−(x+y)
=x+y+2−x−y
=2
∴ Jim was left with 2 candies.