我有一个对角矩阵,我正在尝试为矩阵的总和编写一个函数。
这是我到目前为止所拥有的:
import java.io.*;
public class DiagonalMatrices
{
public static void main(String[] args) throws IOException
{
double matrix[][] = {
{10,0,0,0,0},
{0,10,0,0,0},
{0,0,5,0,0},
{0,0,0,-10,0},
{0,0,0,0,7}
};
int j = 0, k = 0;
double sum1 = 0, sum2 = 0;
for ( j = 0; j < matrix.length; j++)
{
for (k = 0; k < matrix.length; k++)
System.out.print(matrix[j][k] + " ");
System.out.println();
}
for ( j = 0; j < matrix.length; j++)
{
sum1 = sum1 + matrix[j][j];
}
k = matrix.length - 1;
for ( j = 0; j < matrix.length; j++)
{
if (k >= 0)
{
sum2 = sum2 + matrix[j][k];
k--;
}
}
System.out.println("Sum of Digonal elements are :" + sum1 + " and " + sum2);
}
}`
我收到 100 个错误,所有人都在说...
“非法字符:\0”
谁能帮忙?