7:45 pm - Thursday April 25, 2019

Java Example Program to find the Transpose of 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
//Example Program to find the Transpose of matrix
/**
 * @author:candid java.com
 * @Descrption:check the matrix is Transpose or not
 */
public class Trans {
	public static void main(String args[]) {
		// initialize the variable
		int[][] a = { { 5, 1, 1 }, { 3, 6, 0 }, { 0, 5, 9 } };
		// print the matrix
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				System.out.print(a[i][j]);
			}
			System.out.println();
		}
		// operation for transpose
		for (int i = 0; i < 3; i++) {
			for (int j = i + 1; j < 3; j++) {
				int temp = a[i][j];
				a[i][j] = a[j][i];
				a[j][i] = temp;
			}
			System.out.println();
		}
		System.out.println("Transpose matrix:");
		// After Transpose the matrix print the result
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				System.out.print(a[i][j]);
			}
			System.out.println();
		}
	}
}

OUTPUT:
5 1 1
3 6 0
0 5 9
Transpose Matrix:
5 3 0
1 6 5
1 0 9

Filed in: Z-A All Java Codes

Comments are closed.