我想填充我与来自回路双值双数组,但我得到以下错误: 不兼容的类型:双重可能有损转换成int填充双值双阵列
,这里是我的代码:
public class ThreadGraph extends Thread {
//initializing the variables
public static double x1=0.0; //left endpoint of interval
public double x2=1.0; //right endpoint of interval
public double y=4/(1+Math.pow(x1, 2)); //Deriving the two parallel trapezium lengths
public int n=1000000; //The Number of trapezia, 1000000 gives greater accuracy for deriving pi
public double h=(x2-x1)/n; //Each trapezium's constant height
public double trapeziaAreasSum=0; //This variable will store the sum of the areas of the trapezia
static double[]valuesOfx1=new double[1000000];
static double[]valuesOfy=new double[1000000];
//this method divides the area under the curve into trapezia
public void run(){
for(double x1=0.0; x1<1.0; x1=x1+0.000001, y=4/(1+Math.pow(x1,2))){
valuesOfx1[x1] = x1; //ERROR OCCURS HERE
valuesOfy[y] = y; //ERROR OCCURS HERE
}}}
可能是什么问题?因为循环的输出是双倍的形式,我试图将这些结果添加到双数组,但我得到一个int错误:不兼容的类型:可能有损从双转换为int