using array

using array

transpose a matrix?

View Answers

May 25, 2012 at 4:09 PM

Java find transpose of matrix

The given code determine the transpose of a matrix.The transpose of a matrix is formed by interchanging the rows and columns of a matrix such that row i of matrix becomes column i of the transposed matrix. The transpose of A is denoted by AT. Through the following code,the user is allowed to enter the number of rows and columns and the elements to create a matrix. Then using the for loop statements, turn all the rows of the matrix into columns and vice-versa.

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:
using array
using array  Circular left shift array element by one position
using array
using array  Circular left shift array element by one position
Advertisements
using array
using array  display 10 digit number using array and print pyramid. 1 1 1 1 1 1 1 1 1 1 1 1
using array
using array  transpose a matrix
using array
using array  transpose a matrix
using array
using array  column wise total of a matrix
using array
using array  read 10 digit number and display (star
using 2D Array
using 2D Array  Write a JAVA program using 2D Array to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C... the class average. Define the exam answer key as Final Array in your program
using 2D Array
using 2D Array  Write a JAVA program using 2D Array to auto-grade exams. For a class of N students, your program should read letter answers (A, B, C... the class average. Define the exam answer key as Final Array in your program
Java Programming using array
Java Programming using array  I'm creating a programming using array... Program: import java.io.*; public class Array { public static void main(String args...','H','J','K','L','M','N','P','Q','R','S','T','V','W','X','Y','Z'}; char ch
Finding duplicates using array in for loop
Finding duplicates using array in for loop  how to find the duplicates in array using for loop
one dimensional array using java
one dimensional array using java  design and implement a java program that will read a file containing numbers and compute the following statistics: the range(low,high) the average and the median
Using [] operator of EL with an Array
Using [ ] operator of EL with an Array   .... An array is a type of container which can hold a fixed number of values of a single type. Array is a collection of similar data types. It means if you have declared
example to booking ticket cinema using array
example to booking ticket cinema using array   example to booking ticket cinema using array
How to using Binary Search Array Java ?
How to using Binary Search Array Java ?  Hi, I am beginners in Java Programming Language. I am trying to create small application using Array functions. The problem is that how to use binary search array in Java. Please give
how to create a zip by using byte array
how to create a zip by using byte array  hi, How to convert byte array to zip by using java program.can u plz provide it...... Thanks, krishna
How to save array of UserType in Oracle using Hibernate.
How to save array of UserType in Oracle using Hibernate.  Hi How to save array of UserType in Oracle using Hibernate. CREATE OR REPLACE TYPE...()); ARRAY array =new ARRAY(arrdesc, arg0.getConnection(), null
How to create binary search tree using an array?
How to create binary search tree using an array?  hello people, pls guide me on the topic above. i have an string array, i want to make a binary search tree based on data inside this array. the array contains names of people
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
To find first two maximum numbers in an array,using single loop without sorting array.
To find first two maximum numbers in an array,using single loop without sorting array.  Java program to find first two maximum numbers in an array,using single loop without sorting array
Display tow dimensional array using one for loop in java
Display tow dimensional array using one for loop in java  Display tow dimensional array using one for loop in java
Convert a string representation of a hex dump to a byte array using Java?
Convert a string representation of a hex dump to a byte array using Java?  Convert a string representation of a hex dump to a byte array using Java
how to Insert Array Values Into Separate Rows using java?
how to Insert Array Values Into Separate Rows using java?  how to Insert Array Values Into Separate Rows using java?  class...) { String array[][]={{"1","Angel","Delhi"},{"2","John","Chennai"},{"3","William
Display tow dimensional array by matrix form using one for loop in java
Display tow dimensional array by matrix form using one for loop in java  Display tow dimensional array by matrix form using one for loop in java
Calculating the checksum of a Byte Array by using Adler32
Calculating the checksum of a Byte Array by using Adler32... of a Byte Array using Adler32. Adler32: It is a error checking technique used... field whose type is byte. To calculate the Checksum of the Byte Array by using
using getText() to retrieve text from an array of text fields with loop.
using getText() to retrieve text from an array of text fields with loop.   hi, I have an array of about 50 textfields which show up when somebody presses button. Now I want to get the text from all the textfields using array
Access value of array using OGNL in struts2.
Access value of array using OGNL in struts2. Here, you will see how to access value of  array in struts2 using OGNL.  1-index.jsp <%@taglib...] : <s:property value="name[0]"/><br/> Value array list
how to convert string to char array in java without using tochararray
how to convert string to char array in java without using tochararray ...() function. how to convert string to char array in java without using... to char array in java without using tochararray: package my.app; public
Array
Array  How do i insert elements into an array up to a limit from command prompt using SOP statement.like Enter range:3 Enter elements: 1 5 3  ...("Enter Range: "); int size=input.nextInt(); int array[]=new int[size
Array of String using Pointers
Array of String using Pointers       In this section, you will learn how to create an array of string using pointers in C. The declaration of an array of character pointers
in_array
in_array  in_array in php
is _array()
is _array()  is_array() in php   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
is _array()
is _array()  is _array()   Hi Friend, This function is of Boolean type.It checks whether a variable is an array or not. Here is an example: <?php $yes = array('Hello', 'World'); echo is_array($yes) ? 'Array
array
array  take a 2d array and display all its elements in a matrix fome using only one for loop and ple explain the program in below
how to insert array data into sql server using jsp
how to insert array data into sql server using jsp  hello, i have problem to insert array data into my sql server from jsp form. beloW is my code . From system.out.prinln, it show 1 record only in printed what i'm already keyin
array
accepts a pointer to integer which represents an array of integer.After that this method prints the entire of the array numbers to the monitor. include using std::cout; using std::endl; void printArray(int *array, int count
Identifying array using Reflection
Identifying array using Reflection   ... the object is Array or not ? with the use of boolean method isArray(). Here... of Array object. In our example we are taking two variable objects of type integer
Array
Array  how can i use elements of an array in a circular form? that is if the searching of the element reach the last elements of the array, then it will start serching from the begining of the array
Array
Array  is it possible to define array like this..? int[] intArray = new int[] {4,5,6,7,8}; Explain...?   Yes, you can. Java Initialize Array
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  write and test a function named mirror that is passed an array of n floats and returns a newly created array that contains those n floats... the array {10.1,11.2,8.3,7.5,22} into{22,7.5,8.3,11.2,10.1
array
array  WAP in java to store 6 element in array P and 4 element in array Q. Produce the third arra y R containing all element from p & q
array
array  array memory allocation is dynamic or static in java   Java Arrays have dynamic memory allocation
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
i need to print customer[1] is abcd,cbnb using array
i need to print customer[1] is abcd,cbnb using array  print("code sample"); package bankprj3; class Account { private double Balance; public Account(double initBalance){ Balance=initBalance; } public
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element
array
array  create an array in which no element is duplicate. if duplicate then tell to user duplicate. duplicacy is tell to user during when he enter the element

Ads