Moving Zeroes- Why this submission not works?

	int countZero =0;
	for(int i=0; i<n;i++){
		if(a[i]==0)
			countZero++;
	}
	for(int i=n-1;i>n-1-countZero;i--){
		int x = 0, temp, j;
		for(j=i;j>=0;j--) {
			temp = a[j];
			if(x!=0||j==i)
				a[j]=x;
			x = temp;
		}
	}
	for(int i=0;i<n;i++){
		System.out.print(a[i]+" ");
	}