main(Eclipse)中未解决的错误

时间:2017-09-01 05:14:11

标签: java eclipse

所以我不断收到此错误消息,我不知道它意味着什么或如何回应。继承我的代码。当我去一个不同的编译器,我没有得到这个问题。提前谢谢!

import java.math.*;
import java.util.*;

public class QuestionEight {

    public QuestionEight() {
        // TODO Auto-generated constructor stub
    }

    public static void main(String [] args) {
        // TODO Auto-generated method stub
        int[] newArr = new int[1000];
        for(int a = 0; a<1000; a++) {
            newArr[a] = countNumbers();
        }
        double sum = (double)sumOfArray(newArr);
        double attempts = (double)1000;
        System.out.println("The average is " + sum/attempts);
    }
    public static int countNumbers() {
        int sum = 0;
        int counter = 0;
        while(sum<1) {
            sum = Math.floor(10.0*Math.random());
            counter++;
        }
        return counter;
    }
    public static int sumOfArray(int[]a) {
        int[] tempArr = new int[a.length];
        for(int c = 0; c<a.length; c++)
            tempArr[c] = a[c];
        for(int d = 1; d<a.length; d=d+2) {
            tempArr[d] = tempArr[d] + tempArr[d-1];
            if(d==tempArr.length-1) {
                return tempArr[d];
            }
        }
        return 0;
    }
}

1 个答案:

答案 0 :(得分:0)

您的代码看起来不错,但您可能想要更改

sum = Math.floor(10.0 * Math.random());

sum = (int) Math.floor(10.0 * Math.random());

因为Math.floor返回的值为double