Deloitte interview question

Simple Java codes