transpose of matrix

Ads
 

transpose of matrix

write a program in java to declare a square matrices 'A' or order n which is less than 20.allow in user to input only positive integers into the matrix and print the transpose of it.

View Answers

February 8, 2011 at 2:41 PM

Java Find Transpose of Matrix

import java.util.*;

public class Transpose {
        public static void main(String[] args) throws Exception {
                int rows, cols;
                int[][] matrix, tmatrix;
                Scanner input = new Scanner(System.in);
                System.out.print("Enter number of rows: ");
                rows = input.nextInt();
                System.out.print("Enter number of columns: ");
                cols = input.nextInt();
                matrix = new int[rows][cols];
                tmatrix = new int[cols][rows];
                System.out.println("Enter elements for Matrix");
                for (int i = 0; i < rows; i++) {
                        for (int j = 0; j < cols; j++) {
                                matrix[i][j] = input.nextInt();
                        }
                }
                for (int i = 0; i < rows; i++) {
                        for (int j = 0; j < cols; j++) {
                                tmatrix[i][j] = matrix[j][i];
                        }
                }
                System.out.println("Matrix is:");
                for (int i = 0; i < rows; i++) {
                        for (int j = 0; j < cols; j++) {
                                System.out.print(matrix[i][j] + " ");
                        }
                        System.out.println();
                }
                System.out.println("Its transpose is: ");
                for (int i = 0; i < cols; i++) {
                        for (int j = 0; j < rows; j++) {
                                System.out.print(tmatrix[i][j] + " ");
                        }
                        System.out.println();
                }
        }
}

Ads









Related Tutorials/Questions & Answers:
transpose of matrix
transpose of matrix  write a program in java to declare a square matrices 'A' or order n which is less than 20.allow in user to input only positive integers into the matrix and print the transpose
transpose matrix
integers into the matrix and print the transpose of it. for this program u r given answer but if i entered 2 by 3 matrix it will not give answer ple check it once...transpose matrix  write a program in java to declare a square
Advertisements
transpose
transpose  how to write transpose of a matrix a program
ModuleNotFoundError: No module named 'transpose'
ModuleNotFoundError: No module named 'transpose'  Hi, My Python... 'transpose' How to remove the ModuleNotFoundError: No module named 'transpose' error? Thanks   Hi, In your python environment you
ModuleNotFoundError: No module named 'transpose-dict'
ModuleNotFoundError: No module named 'transpose-dict'  Hi, My... named 'transpose-dict' How to remove the ModuleNotFoundError: No module named 'transpose-dict' error? Thanks   Hi, In your python
matrix addition
matrix addition  hai
matrix addition
matrix addition  hai
matrix substraction
matrix substraction  hai
matrix substraction
matrix substraction  hai
matrix adddition
matrix adddition   how to write a program matrix addition in java
column matrix
column matrix  columan wise total matrix
column matrix
column matrix  columan wise total matrix
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
Matrix Class
Matrix Class   A class to manage matrices and add them. Create in the driver class two objects of it and use the add method
matrix determination in java
matrix determination in java  hai
matrix polynamial addtion
matrix polynamial addtion  hai
matrix
Magic Matrix in GUI
Magic Matrix in GUI  I want program in java GUI contain magic matrix for numbers
ModuleNotFoundError: No module named 'matrix'
ModuleNotFoundError: No module named 'matrix'  Hi, My Python... 'matrix' How to remove the ModuleNotFoundError: No module named 'matrix'... to install padas library. You can install matrix python with following command
ModuleNotFoundError: No module named 'the-matrix'
ModuleNotFoundError: No module named 'the-matrix'  Hi, My Python... 'the-matrix' How to remove the ModuleNotFoundError: No module named 'the-matrix' error? Thanks   Hi, In your python environment you
Parallel multiplication matrix in java
Parallel multiplication matrix in java  hello dear I need parallel multiply matrix in java algorithm to account speed up and efficiency great wishes
parallel dense matrix multiplication
parallel dense matrix multiplication  hi friends, i am a final year... using dense parallel matrix multiplication. I request you to kindly provide me a code for Parallel Matrix multiplication on distributed systems using Java
Matrix Addition using RMI in Java
Matrix Addition using RMI in Java  Source Code for Matrix Addition using RMI in Java
Javascript matrix error
Javascript matrix error  This function blows up (without an error) whenever it is called function valid(n){ //n is a number 0-9 if(board...; } } where board is a global 3x3 Array matrix var board = new Array(3
TensorFlow placeholder matrix
matrix with TensorFlow? I am searching for TensorFlow placeholder matrix... matrix and it can easily perform various operations on the matrix. In the following example we are defining a multi-dimensional matrix as placeholder
ModuleNotFoundError: No module named 'backends-matrix'
ModuleNotFoundError: No module named 'backends-matrix'  Hi, My... named 'backends-matrix' How to remove the ModuleNotFoundError: No module named 'backends-matrix' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'isdc-matrix'
ModuleNotFoundError: No module named 'isdc-matrix'  Hi, My Python... 'isdc-matrix' How to remove the ModuleNotFoundError: No module named 'isdc-matrix' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'luma.led_matrix'
ModuleNotFoundError: No module named 'luma.led_matrix'  Hi, My... named 'luma.led_matrix' How to remove the ModuleNotFoundError: No module named 'luma.led_matrix' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'matrix-algebra'
ModuleNotFoundError: No module named 'matrix-algebra'  Hi, My... named 'matrix-algebra' How to remove the ModuleNotFoundError: No module named 'matrix-algebra' error? Thanks   Hi, In your python
ModuleNotFoundError: No module named 'matrix-architect'
ModuleNotFoundError: No module named 'matrix-architect'  Hi, My... named 'matrix-architect' How to remove the ModuleNotFoundError: No module named 'matrix-architect' error? Thanks   Hi, In your
ModuleNotFoundError: No module named 'matrix-array'
ModuleNotFoundError: No module named 'matrix-array'  Hi, My Python... 'matrix-array' How to remove the ModuleNotFoundError: No module named 'matrix-array' error? Thanks   Hi, In your python

Ads