i am new in coding actually "very new". it can be silly question but i dare it:) here is the question The method should have the parameter int n and the result should be an animal array of length n, the randomly chosen animal contains. Proceed as follows: First create one empty array of corresponding length. Loop through the array. Generate in a random value r for each run using the static method RandomTools.randomValue between 0 and Animal.values (). length (exclusive). Assign this to the current array position Enumeration element with the corresponding ordinal number for (Animal.values () [r]). You can assume that n is positive.(the current enum is not important i think it was just a name bunch of animals like elephant tiger and so on)enter code here
public static void main(String[] args) {
Animal[] zoo = generateRandomZoo(100);
private static Animal[] generateRandomZoo(int n) {
int [] Animal = new int [n];
for(int i =0; i<5;i++){
System.out.println(RandomTools.randomValue(100));
}
return null;
}
}
Aucun commentaire:
Enregistrer un commentaire