It's say's type mismatch.... even if an appropriate type is selected....
I am attaching the code for better understanding....
public void calucate()
{
int Sum=0;
arraySumOfRows= new int[20];
for(int i=0;i<Array1.length;i++)
{
for(int j=0;j<Array1.length;j++)
{
Sum=Sum+Array1[i][j];
arraySumOfRows[i]=Sum;
}
}
for(int i=0;i<arraySumOfRows.length;i++)
System.out.println(Arrays.toSt开发者_高级运维ring(arraySumOfRows[i]));
}
Two problems:
arraySumOfRows[i]
is an integer andArrays.toString()
expects an array. Just use:System.out.println(arraySumOfRows[i]);
Your inner loop is wrong. I should be:
for(int j=0;j<Array1[i].length;j++)
Try this:
notice i moves the line arraySumOfRows[i]=Sum
out of the internal (j)loop, i think it belongs to the external one (i)Loop.
public void calucate()
{
int Sum=0;
arraySumOfRows= new int[20];
for(int i=0;i<Array1.length;i++)
{
for(int j=0;j<Array1.length;j++)
{
Sum=Sum+Array1[i][j];
}
arraySumOfRows[i]=Sum;
}
for(int i=0;i<arraySumOfRows.length;i++)
System.out.println(Integer.toString(arraySumOfRows[i]));
}
精彩评论