7:28 pm - Thursday August 17, 2017

Java Example Program for inverse matrix

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044

public class Matrix 

{

	public static void main(String[] args) 
	
	{

		// array creation and allocated memory
		int[][] array = new int[3][3];
		// to initialize the values
		array[0][0] = 1;
		array[0][1] = 2;
		array[0][2] = 3;
		array[1][0] = 4;
		array[1][1] = 5;
		array[1][2] = 6;
		array[2][0] = 7;
		array[2][1] = 8;
		array[2][2] = 9;
		// to print the matrix array
		System.out.println("Matrix");
		for (int i = 0; i < 3; i++) 
		{
			for (int j = 0; j < 3; j++) 
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.print("\n");
		}

		// 	to print the inverse of matrix array
		System.out.println("Inverse of Matrix");
		for (int i = 0; i < 3; i++) 
		{
			for (int j = 0; j < 3; j++) 
			{
				System.out.print(array[j][i] + " ");
			}
			System.out.print("\n");
		}

}

}

Output:

Matrix

1 2 3

4 5 6

7 8 9

Inverse of Matrix

1 4 7

2 5 8

3 6 9

 

Filed in: Sample Programs in java

Comments are closed.