Caterpillar interview question

java