Did problem 12 in java