Cognizant interview question

Few basic Java codes