我试图在数组中插入双精度数(D [i] [j] = distance;),但出现此错误:需要数组但找到了双精度!我看不到我的错误!请帮助 这是代码:
public static double[] D=new double[1000];
public static void main(String[] args) {
// Data points matrice: X
double X[][] = { {0.5,0.3,0.25,0.4},
{0.4,0.33,0.26,0.7},
{0.1,0.9,0.34,0.77},
{0.1,0.98,0.28,0.4},
{0.75,0.63,0.51,0.6}};
for (int i=0; i<X.length-1;i++){
for (int z=0; z<X.length; z++){
double d=0;
for (int j=0; j<X[i].length;j++){
if (i!=z){
System.out.println(X[i][j]+"et"+X[z][j]);
d=d+Math.pow((X[i][j]-X[z][j]),2);
}else {d=0;}
System.out.println(d);
double distance= Math.sqrt(d);
D[i][j]=distance;
}
System.out.println("*****");
}
答案 0 :(得分:0)
D[i] = distance;
是一维阵列,而不是2D阵列
我想你打算写
D
如果没有,那么您需要将(?:287434|383460|633491|717255|827734|253735|635373|553888|910366)
从一维数组更改为二维数组
答案 1 :(得分:0)
如果将D
的声明更改为以下内容,它将起作用:
public static double[][] D = new double[5][5];
这使D
成为二维数组而不是一维数组。