import java.util.Random;
class Moo {
public static void main(String[] args) {
Random rand = new Random();
System.out.println("Index\tValue");
int randnumb = 1 + rand.nextInt(11);
int array[] = new int[5];
array[0] = randnumb;
array[1] = randnumb;
array[2] = randnumb;
array[3] = randnumb;
array[4] = randnumb;
for (int counter=0; counter < array.length; counter++)
System.out.println(counter + "\t" + array[counter]);
}
}
问题:每个元素都有相同的值,但我希望每个元素都有随机和不同的值。