added java solutions for reference