Java创建一个4行4列的double型数组并保存随机数,计算每一行元素之和保存在一维数组中,用增强型for输

2024-11-26 22:26:51
推荐回答(1个)
回答1:

import java.util.*;
class test{
public static void main(String[] args){
double[][] t = new double[4][4];
double[] sum = new double[4];
Random r = new Randon();
for(int i=0;i<4; i++){
sum[i] = 0;
for(int j=0;j<4; j++)
t[i][j] = r.nextDouble();
sum[i] += t[i][j];
}
}
int i=0;
for(double d : sum){
System.out.println("第" + (i++) + "行的和的值为:"+ d);
}
}
}