Ok I will post what I have for Java code at the end but here is what I need it to do. In the main method a boolean array called Lights is declared which runs through how_many (declared int).
Then I have to call a method called initialize which I am to pass in the lights array along with the size of the lights array as the first and second arguments (respectively).
This is followed by a for loop that calls the method do_pass over and over until I reach the end of how_many and toggles each array position either true or false. This will then start at the second position and if true will toggle false or if false will toggle true. It will do this until it starts at how_many and ends at how_many.
It will then print out how many are toggled true (on) by calling the method how_many_are_on
Here is my code so far:
import java.util.Scanner;
public class Lab7
{
public static void main(String args[])
{
Scanner stdin = new Scanner(System.in);
int how_many = stdin.nextInt();
boolean [] lights = new boolean [how_many];
initialize (lights[0].how_many);
for (int a = 0; a < how_many; a++)
do_pass(lights.length);
}
public static void initialize (boolean [] resets, int size)
{
for (int i = size; i < size; i++)
if (lights[how_many] == true)
lights[how_many] = false;
}
public static void do_pass(boolean lights[], int start, int end, int skip)
{
for (int index = start; index < end; index += skip)
lights[index] = !(lights[index]);
}
public static int how_many_are_on(boolean lights[], int size)
{
int sum = 0;
for (int count = 0; count < size ; count++)
{
if (lights[count] == true)
{
return true;
sum ++;
}
}
return false;
}
}