I am trying to understand why the following program won't print an array in the data type double and then calculate the trace and normal. The array is aimed to be a 5 by 5 array
import java.io.*;
public class Practice
{
//size of the given matrix
static double MAX = 10;
//the method calculates and returns Normal of a matrix
static double calculateNormal(double matrix[][], double n)
{
double sum = 0;
for (double i=0; i<n; i++)
for (double j=0; j<n; j++)
sum = sum + matrix[i][j]*matrix[i][j];
return (double)Math.sqrt(sum);
}
//the method calculates and returns trace of a matrix
static double calculateTrace(double matrix[][], double n)
{
double sum = 0;
for (double i=0; i<n; i++)
sum = sum + matrix[i][i];
return sum;
}
//driver code
public static void main (String args[])
{
//initializing matrix elements
double matrix[][] = {{17.5, -2.9, 9.8, -18.8, 14.5},
{4.9, 11.6, -4.2, -8.6, -19.3},
{-10.7, 14.5, -15.3, -16.9, 4.7},
{-2.5, -4.4, 2.2, 13.7, -16.6},
{4.2, -18.7, -3.9, -14.5, 16.8},
};
System.out.println ("Trace of the give matrix is: "+ calculateTrace(matrix, 5));
System.out.println ("Normal of the given matrix is: "+ calculateNormal(matrix, 5));
}
}