IBM Interview Question

Rewrite the above in Java.