Java: Change every 2nd Element, then every 3rd and so on... (Array)

im stuck at a particular homework task. The task is:

to iterate a booelean-array 100 times and set all elements to false on the first iteration.

Then change every 2nd element on the 2nd iteration (set false->true / set true->false)

every 3rd element on 3rd iteration

...

My code:

I've tried different increments at the for-loop which changes the status, but cant get it to look like the expected result.

@Override

public String toString() {

if (this.status==false) {

return "z";

} else {

return "o";

}

}

public static void main(String[] args) {

Locker[] door = new Locker[100];

for (int i = 0;i
door[i] =...

Read More »

By: StackOverFlow - 5 days ago

Related Posts