0

I take a computer science projects class, and I've been working on a project and I'm stuck. I have to write a program that has 5 riddles and 5 answers. I'm having trouble trying to repeat elements in an array randomly, without repeating the same element twice. I do know that it has something to do with int [] repeat, but otherwise I have no idea what I'm doing. My teacher told me to use this code somehow:

int[]repeat= new int[5];   This goes with other array declarations.
repeat = {0,0,0,0,0}
index = rand.nextInt(5);

while(repeat[index] ==1)   This goes before you post a riddle
{
index = rand.nextInt(5);
}

System.out.println("The riddle is " + repeat[Index]==1);

how would I use this to repeat elements in the array randomly, without the same element repeating twice?

1 Answers1

0

It looks as though you're to use the repeat array to track whether the riddle has been posed (0 is posable, 1 is already posed). I'm guessing you'll have a Map of the riddles as well, where the integer is the 0..4. The System.out.println doesn't seem to make any sense to me, other than it being check that you indeed have a valid riddle.

adamdc78
  • 1,153
  • 8
  • 18