I want to learn how can i pick a string value from enum and run in for-each loop.Let me write the Assignment here; "Write a static method generateRandomZoo (n). The
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." What i ve done is as follows enter code here
first of all enum class looks like; package main;
公共枚举动物{
ELEPHANT,LION, TIGER, WASP, SNAKE,MONKEY, EMU;
}
主要的编码部分是这样
公共静态void main(String [] args){
Animal[] zoo = generateRandomZoo(100);
}
私人静态Animal [] generateRandomZoo(){ // TODO自动生成的方法存根
Animal [] animals= new Animal [100] ;
for(Animal a : Animal.values()){
System.out.println("Random Animals"+ "-" + a + "-" +(a.ordinal()+1));
for (int i = 0; i<100 ; i++) {
animal[i] = random animal
System.out.println(i);
}
private static RandomTools.randomValue();
}
你能告诉我我错了哪里以及如何纠正它吗?(通过我很漂亮的初学者的方式,请以我能理解的方式描述:))