code related question the working procedure

Viewed 29

wanted to know when segregating 0's and 1's:

 int [] arr ={0,1,0,1,0,1,0,1,0,1,1,0};
        int j = 0;

        //traverse the array
        for(int i=0; i < arr.length; i++){

            if(arr[i]==0){
                arr[j++] = arr[i];
            }
        }
        while(j<arr.length){
            arr[j++] = 1;
        }
        for(int k=0; k<arr.length; k++){
            System.out.println(arr[k] + " ");

the last part to print the new array we used int k arr[k], does that automatically joins the 0's and 1's ?

0 Answers
Related