[英]Unresolved error in main (Eclipse)
So i keep getting this error message and i have no idea what it means or how to respond.因此,我不断收到此错误消息,但我不知道它的含义或如何响应。 Heres my code.继承人我的代码。 When i go to a different compiler, i dont get this issue.当我转到不同的编译器时,我没有遇到这个问题。 Thanks in advance!提前致谢!
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;
}
}
Your code looks fine, except that you might want to change您的代码看起来不错,只是您可能想要更改
sum = Math.floor(10.0 * Math.random());
to到
sum = (int) Math.floor(10.0 * Math.random());
since Math.floor
returns a value of type double
.因为Math.floor
返回一个double
类型的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.