簡體   English   中英

main (Eclipse) 中未解決的錯誤

[英]Unresolved error in main (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;
    }
}

您的代碼看起來不錯,只是您可能想要更改

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

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

因為Math.floor返回一個double類型的值。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM