Cognizant Interview Question

Few puzzles to be coded in java.