Did #41 in java