by Dinesh Thakur

 

import java.io.*;

class Matrix2x4
{
            public static void main(String args[])
            throws IOException
            {
                        BufferedReader k=new BufferedReader(new InputStreamReader(System.in));
                        int m[][]=new int[2][4];
                        int i,j;
                        String s;
                        System.out.println("Enter Elements of a Matrix of order 2 x 4");
                        for(i=0;i<=1;i++)
                        {
                                    for(j=0;j<=3;j++)
                                    {
                                                s=k.readLine();
                                                m[i][j]=Integer.parseInt(s);
                                    }
                        }
                        System.out.println("The Original Matrix entered is ");
                        for(i=0;i<=1;i++)
                        {
                                    for(j=0;j<=3;j++)
                                    {
                                                System.out.print(m[i][j]+"\t");
                                    }
                                    System.out.println();
                        }
                        System.out.println("The Transpose of the Matrix is ");
                        for(i=0;i<=3;i++)
                        {
                                    for(j=0;j<=1;j++)
                                    {
                                                System.out.print(m[j][i]+"\t");
                                    }
                                    System.out.println();
                        }
            }
}

2x4 Matrix in Java Example