Cognizant interview question

Java sample program