Beginner solution in java