Manipulating array elements to zero using for-loops and if-statements in Java
So I've been working on my Java CompSci assignment, and I've spent quite some time getting to where I am and I just need one final push over the hill.
The first part I've finished, it was to create a method called findZero that finds the first zero in an array and return the index. It works with what I think is one exception. When the first zero in my array is also the last element in my array, it doesn't seem to work. I cannot see how to simply fix this. I could make the array one bigger than I need every time and not print the final integer, which I will do if no better ideas come to me.
The second part is much more irksome. The assignment reads as follows:
Write method setZeros. Method setZeros should find the positions of the first two zeroes in its array parameter A, and it should set all of the intervening values to zero. If A only contains one zero, or if the first two zeros are right next to each other, setZeros should not modify A.
I was thinking that I'll first create a backup of the inputted array and use it to return if any of the no-edit conditions are true. As of now, I've used a combination of for loops and if statements to try to do what the programme design asks for, although my program currently replaces all zeroes after to first zero with zero.
My code is available here:
and I'll keep an eye on the chat there, although I'd prefer to discuss here and then I'll try to figure out the changes.
Any and all help, advice, or comments are much appreciated.
Example of current output at 25 elements
Any questions of information I've not given welcome.