added homework 2.2 in Java