//Compressed Row Storage format for a sparse square matrix public class CRS{ //the values of the nonzero elements of the matrix float[] val; //the column indices of the elements in the val vector int[] col_idx; //locations in the val vector that start a row //the size is decided by the size of the matrix int[] row_ptr; //the number of rows of the matrix int mSize=0; //constructor that takes a sparse matrix and convert it to a CRS object CRS( float[][] matrix){ int i;//row index int j;//column index int totalNonZeros;//the total number of nonzero in the matrix int index; //get the number of rows and columns mSize = matrix.length; System.out.println("the size of the matrix is:"+mSize+"X"+mSize+"\n"); //find the number of nonzero entries in the matrix totalNonZeros = 0; for(i=0; i