Java Code for Square Matrix

This java programming code is used to find the square matrix . You can select the whole java code by clicking the select option and can use it. When you click text, the code will be changed to text format. This java program code will be opened in a new pop up window once you click pop-up from the right corner. You can just copy, paste this java code and use it to find the square matrix .

import java.util.*;
import java.lang.*;
class  Square_matrix
{  
 public static void main(String args[])
   {  
 int  matrix_2[][]={{3,5},{2,6}};
 int matrix_3[][]={{3,5,1},{2,6,7},{1,7,3}};
 int r1=0,r2=0,r3=0,r4=0;
 //2*2 Matrix Square
 r1 = (matrix_2[0][0]*matrix_2[0][0])+(matrix_2[0][1]*matrix_2[1][0]);
 r2 = (matrix_2[0][0]*matrix_2[0][1])+(matrix_2[0][1]*matrix_2[1][1]);
 r3 = (matrix_2[1][0]*matrix_2[0][0])+(matrix_2[1][1]*matrix_2[1][0]);
 r4 = (matrix_2[1][0]*matrix_2[0][1])+(matrix_2[1][1]*matrix_2[1][1]);
 System.out.println("Matrix Square(2*2):
 "+r1+" "+r2+"
 "+r3+" "+r4);
 //3*3 Matrix Square
 int x11 = (matrix_3[0][0]* matrix_3[0][0]) + (matrix_3[0][1] * matrix_3[1][0]) +  (matrix_3[0][2]* matrix_3[2][0]);
 int x12 = (matrix_3[0][0]* matrix_3[0][1]) + (matrix_3[0][1] * matrix_3[1][1]) +  (matrix_3[0][2]* matrix_3[2][2]);
 int x13 = (matrix_3[0][0]* matrix_3[0][2]) + (matrix_3[0][1] * matrix_3[1][2]) +  (matrix_3[0][2]* matrix_3[2][2]);
 int x21 = (matrix_3[1][0]* matrix_3[0][0]) + (matrix_3[1][1] * matrix_3[1][0]) +  (matrix_3[1][2]* matrix_3[2][0]);
 int x22 = (matrix_3[1][0]* matrix_3[0][1]) + (matrix_3[1][1] * matrix_3[1][1]) +  (matrix_3[1][2]* matrix_3[2][1]);
 int x23 = (matrix_3[1][0]* matrix_3[0][2]) + (matrix_3[1][1] * matrix_3[1][2]) +  (matrix_3[1][2]* matrix_3[2][2]);
 int x31 = (matrix_3[2][0]* matrix_3[0][0]) + (matrix_3[2][1] * matrix_3[1][0]) +  (matrix_3[2][2]* matrix_3[2][0]);
 int x32 = (matrix_3[2][0]* matrix_3[0][1]) + (matrix_3[2][1] * matrix_3[1][1]) +  (matrix_3[2][2]* matrix_3[2][1]);
 int x33 = (matrix_3[2][0]* matrix_3[0][2]) + (matrix_3[2][1] * matrix_3[1][2]) +  (matrix_3[2][2]* matrix_3[2][2]);
 System.out.println("
Matrix Square(3*3):
"+x11+" "+x12+" "+x13+"
"+x21+" "+x22+" "+x23+"
"+x31+" "+x32+" "+x33);
   }
}
Other Programming Codes
Online Calculator : Square Matrix Calculator
Click on the select code link to copy and paste this free java program code for square matrix calculator.

english Calculators and Converters


Sitemap