The solutions in java format.