我想填充我與來自迴路雙值雙數組,但我得到以下錯誤: 不兼容的類型:雙重可能有損轉換成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