Added solution in Java