Completed p1 in Java