Finished problem 42 in java