Kaplan interview question

Java Coding