Matrix
Matrix
package Array;
/**
* Write a description of class MatrixA here.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.util.*;
public class MatrixA
{
float [] [] mat;//This instance variable stores the value of a matrix
for(int i = 0; i<r;i+=1)
{
for(int n = 0; n<c; n+=1)
{
System.out.print("Enter the element of row " + (i+1) + " and columns " +
(n+1));
mat[i][n] = sc.nextInt();
}
}
}
//It takes a 2D array and a scalar value and multiplies every array in the element by
a scalar
void scalarMultiplication (float [][] mat , float s)
{
for(int i = 0; i<mat.length;i++)
{
for(int k = 0;k<mat[i].length;k++)
{
mat[i][k] = (mat[i][k])*s;
}
}
printMat(mat);
/**
* Output:
*
* 4.0 6.0
6.0 8.0
*/
}
System.out.println();
}
/**
* Output:
*
* 4.0 6.0
6.0 8.0
*/
}
//This function changes the rows to column and the column to rows
void transposeMat (float [][] mat)
{
float [][] mat_final = new float[mat[0].length][mat.length];
for(int i = 0; i<mat[0].length;i+=1)
{
for(int k = 0;k<mat.length;k++)
{
mat_final[i][k] = mat[k][i];
}
}
printMat(mat_final);
/**
* Output:
*
* 2.0 3.0
3.0 4.0
*/
}
*/
}