Answers for "Write a program for finding the transpose of a 3 x3 matrix in java"

3

java program to find transpose of a matrix

import java.util.Scanner;
public class MatrixTransposeInJava
{
   public static void main(String[] args)
   {
      int[][] arrGiven = {{2,4,6},{8,1,3},{5,7,9}};	    
      // another matrix to store transpose of matrix  
      int[][] arrTranspose = new int[3][3];	    
      // transpose matrix code  
      for(int a = 0; a < 3; a++)
      {    
         for(int b = 0; b < 3; b++)
         {    
            arrTranspose[a][b] = arrGiven[b][a];  
         } 
      }	  
      System.out.println("Before matrix transpose: ");  
      for(int a = 0; a < 3; a++)
      {    
         for(int b = 0; b < 3; b++)
         {    
            System.out.print(arrGiven[a][b] + " ");    
         } 
         System.out.println();
      }    
      System.out.println("After matrix transpose: ");  
      for(int a = 0; a < 3; a++)
      {    
         for(int b = 0; b < 3; b++)
         {    
            System.out.print(arrTranspose[a][b] + " ");    
         } 
         System.out.println();
      }
   }
}
Posted by: Guest on December-30-2020

Code answers related to "Write a program for finding the transpose of a 3 x3 matrix in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language