import java.lang.Math;
public class Homework2 {
public static void main(String[] args){
int d1 = (int) (Math.random()*(10-3+1)+3);
int d2 = (int) (Math.random()*(10-3+1)+3);
double[][] doubMatrix1 = new double[d1][d2];
double[][] doubMatrix2 = new double[d1][d2];
double[][] doubMatrix3 = new double[d1][d2];
doubMatrix1 = getdoubMatrix(d1,d2);
doubMatrix2 = getdoubMatrix(d1,d2);
doubMatrix3 = addMatrices(doubMatrix1, doubMatrix2);
}
public static double[][] getdoubMatrix(int d1, int d2){
double[][] tempArray = new double[d1][d2];
for(int i =0; i <tempArray.length;i++ )
for(int j =0;j < tempArray[i].length;j++)
tempArray[i][j] = Math.random()*(10.0);
return tempArray;
}
public static double[][] addMatrices(double doubMatrix1[][], double doubMatrix2[][]){
for(int i = 0; i< doubMatrix1.length;i++)
for(int j = 0; j< doubMatrix1[i].length;j++ )
{
if(doubMatrix1[i][j] == doubMatrix2[i][j])
{
double[][] tempArray = new double[i][j];
}
else
{
return tempArray[0][0];
}
}
return tempArray;
}
}
我在 addMatrices 方法中的两个 return 语句上都收到错误,我也不认为我做对了
这是我应该为 addMatrices 方法做的
在 addMatrices 方法中,
· 检查每个 2-dim 的第一个尺寸和第二个尺寸。数组数组相同——如果它们不相同,则返回 0 X 0 2-dim。数组,否则执行以下操作;
· 为本地 2-dim 分配内存。与 2-dim 之一具有相同尺寸的数组。数组参数
· 在参数 2-dim 中添加每个对应的元素。数组并将结果存储在本地 2-dim 的相应元素中。数组(使用嵌套的 for 循环)
· 返回本地 2-dim。大批