I have prepared a code to get a random number from an array of integers (1 - 10) to build a multiplication table.
int[] anArrayOne = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int[] anArrayTwo = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int answer;
int firstNumber = new Random().nextInt(anArrayOne.length);
int secondNumber = new Random().nextInt(anArrayTwo.length);
System.out.println("What is" + firstNumber + " times "
+ secondNumber + "? ");
The code sometimes returns "0". Why is it the case if there is no 0 value assigned in neither of the arrays?
Aucun commentaire:
Enregistrer un commentaire