how to terminate printing an array of ints
Posted on 2004-09-29
I have this array of 0s and 1s. Originally the array is initialized to all 1s, and then using this method:
public static int bitSwap(int swapArray)
for (k=0; k < swapArray.length; k++)
if (swapArray[k] == 0)
swapArray[k] = 1;
swapArray[k] = 0;
It switches 1s to 0s and 0s to 1s, but once a 1 has been flipped to 0, the code breaks. This method returns the index at which the 0 was flipped, which is what i need it to do. The user passes an integer value, which determines the size of the array that is passed to this method. My question is this:
I need to print the return statement of this method in a loop of some kind. I know that when the array passed contains ALL 0s in it's indices, then it needs to stop, but I can't figure out how to make it do that.
Help would be appreciated.