class ErweiShuzu
{
public static void main(String[] args)
{
int[][] arr=new int[4][];//后面括号内添加数字有没有影响?为什么?
arr[0]=new int[]{1,2};
arr[1]=new int[]{1,2,3};
arr[2]=new int[]{1,2,3,4};
arr[3]=new int[]{1,2,3,4,5,6};
int sum=0;
for (int i=0;i<arr.length;i++)
{
int groupSum=0;
for (int j=0;j<arr.length;j++)
{
groupSum+=arr[j];
}
sum+=groupSum;
System.out.println("第"+(i+1)+"组的和为"+groupSum);
}
System.out.println("总和为"+sum);
}
} |
|