コードをコンパイルすると、到達不能なステートメントエラーが発生するのはなぜですか。エラーはコードの最後の行(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]);
}
}