Cognizant Interview Question

They asked to provide logic behind a java code question