Added Second Solution (java)