Deloitte interview question

Basic cpp and java codes