CG Infinity Interview Question

Basic java logic