jeudi 21 mai 2015

Random method for a quiz

each method contain a question with multiple choice.When i call the method in the main, i need to shuffle it and make sure there are no repetition.

public static void main(String[] args) { question_1(); question_2(); question_3(); question_4(); //continue to question 15 question_15(); } thing that i tried. int question_A = question_1(); int question_B = question_2(); int question_C = question_3(); int question_D = question_4(); //to question 15 int question_O = question_15(); //then i created an array int [] question = new int[14]; question[0] = question_A; question[1] = question_B; question[2] = question_C; question[3] = question_D; //to last array question[14] = question_O; //to random it here is the code Random r = new Random(); for (int counter = 0; counter <10; ++counter){ int swap_Index = r.next Int(15-counter)+counter; //there is an space between next Int, that because i was getting not properly formatted in the edit box int temp = question[counter]; question[counter] = question[swap_Index]; question[swap__Index] = temp; int[] question_To_Ask = new int[10]; for (int count = 0; count<10; ++count){ question_To_Ask[count] = question[count]; } reason the random does not work is because it start executing the program at int question_A = question_1(); for the random i also tried any way such as Math.random none if these worked and yeah, please do not use advance technique to solve this problem as i'm a beginner




Aucun commentaire:

Enregistrer un commentaire