Because you don't sort the entire array. In this line:
Arrays.sort(p, 5, 9);
you are sorting the array only from the position 5 to 9. Use could use instead:
Arrays.sort(p, 0, p.length);
In this way you are sure that you are sorting the entire array from the first position (index zero) to the last position (the last parameter indicates the last exclusive index).
But it is easier to use:
Arrays.sort(p);
that automatically sort the entire array as explained above.