Thanks a lot. Its really kind of you to help me with this problem. I have understood what you told me, but unfortunately, its still repeating questions( to be precise it is repeating only the last question for 3 to 4 times). This is the code, where i put the source code you told me. I think that there is something wrong with the way "pos" is calculated. But i can't figure it out. Have i have done something wrong? Thanks a lot again and i'm sorry for bothering you. Thanks again. :-)
The code:
public void askQuestions(String[] questions, String[] answers) {
int count = 0;
int point = 0;
int[] A = new int[questions.length];
int[] B = new int[A.length];
int countA = A.length;
int countB = 0;
for (int i = 0; i < A.length; i++){
A[i] = i;
}
while (countA > 0){
Random generator = new Random();
int pos = generator.nextInt(A.length);
B[countB] = A[pos];
countB++;
for (int i = pos; i < A.length - 1; i++){
A[i] = A[i + 1];
}
countA--;
}
for(int j = 0; j < questions.length; j++) {
timeForMore = true;
int randomIndex = B[j];
String input = JOptionPane.showInputDialog(null, questions[randomIndex]);
if(answers[randomIndex].equalsIgnoreCase(input))
count++; // incrementing counter if entered answer is correct
point++;
if(!timeForMore) // if time is over, the program executes the loop an stops asking questions.
break;
}
JOptionPane.showMessageDialog(null, "You answered " + count +
" out of " + questions.length +
" questions correctly.");
}