public class Knn {
public static void main(String[] args) {
int[]a = new int[]{1,1,1,2,2,2,6,2,3,5,4,5,3,3};
int[]b = new int[]{2,3,1,1,2,3,8,4,2,7,7,6,3,4};
for(int i = 0;i<a.length;i++){
int A = a[i]-4;
int B = b[i]-5;
double c = Math.pow(A, 2);
double d = Math.pow(B, 2);
double e = c+d;
double E = Math.sqrt(e);
System.out.println(E);
}
}
}
请问在这里如何对E进行从小到大的排序?
最主要是我不知道怎么存到数组里
追答在for循环之前定义一个数组,数组长度与a应该是一样的
double[] c = new int[a.length];然后在for循环中,把E的值放入数组就好了
c[i] = E;