为什么我在编译代码时会收到无法访问的语句错误。错误出现在代码的最后一行 ( System.out
)。它在 main 方法中,我不明白为什么它无法访问。
public class Count {
public static void main(String[] args) {
Vector numberList = new Vector();
double randomNum;
//for loop to get numbers and add to vector
for (int i = 0; i <= 9999; i++) {
do {
randomNum = Math.random();
} while (randomNum < .01 || randomNum > .99);
//takes the random number, rounds it, and multiplies it by 100
//so that the numbers go from 1 to 99
Math.round(randomNum *= 100);
//converts the double to an int
int tempNum = (int) randomNum;
//the vector is built
numberList.add(i, tempNum);
}
//sorts numbers
Collections.sort(numberList);
int count[] = new int[99];
for (int j = 1;; j++) {
for (int i = 0; i < 9999; i++) {
if ((numberList.elementAt(i)) == j) {
count[j] += 1;
}
}
}
System.out.println(count[1]);
}
}