You have your logic wrong in the final two
while
loops.
try:
while (x < nums.Length)
{
nums2[z] = nums[x];
z++;
x++;
}
while (y < nums1.Length)
{
nums2[z] = nums1[y];
z++;
y++;
}
BTW: Don't forget to make sure that your two input arrays are sorted before starting the merge.