Cognizant interview question

To solve some java questions