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?