
二楼代码
public class Point {
int[][] a=new int[2][10];
double x=0; // x坐标
double y=0; // y坐标
double distance; // 到原点距离
public void Array(){ //二维数组赋值
for(int i=0;i<2;i++){
for(int j=0;j<10;j++){
a[i][j]=(int)(10*Math.random());//值随机
}
}
//组合成10对坐标,并求出到原点距离
for(int j=0;j<10;j++){
x=(double)a[0][j];
y=(double)a[1][j];
distance=Math.pow(Math.pow(x,2)+Math.pow(y,2),0.5);
System.out.println("("+a[0][j]+","+a[1][j]+") 到原点距离 "+distance);
}
}
public static void main(String[] args) {
Point point=new Point();
point.Array();
}
}
public class Point {
int[][] a=new int[2][10];
double x=0; // x坐标
double y=0; // y坐标
double distance; // 到原点距离
public void Array(){ //二维数组赋值
for(int i=0;i<2;i++){
for(int j=0;j<10;j++){
a[i][j]=(int)(10*Math.random());//值随机
}
}
//组合成10对坐标,并求出到原点距离
for(int j=0;j<10;j++){
x=(double)a[0][j];
y=(double)a[1][j];
distance=Math.pow(Math.pow(x,2)+Math.pow(y,2),0.5);
System.out.println("("+a[0][j]+","+a[1][j]+") 到原点距离 "+distance);
}
}
public static void main(String[] args) {
Point point=new Point();
point.Array();
}
}
