MANISHA KUMARI
using array
1 Answer(s)      a year ago
Posted in : Java Beginners

transpose a matrix?

View Answers

May 25, 2012 at 4:08 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();
                    }
            }
    }









Related Pages:
using array
using array  Circular left shift array element by one position
using array
using array  Circular left shift array element by one position
Array
Array  What if i will not declare the limit index of an array, how will I declare an array and store values with it using loop?   Hi Friend...(System.in); int array[]=new int[5]; System.out.println("Enter Array Elements
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
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
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
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
array
array  how to getting values and storing values in array by using datainputstream?   Hi Friend, Try the following code: import java.io....]=Integer.parseInt(br.readLine()); } System.out.println("Array Elements
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
PHP Push Array to Array
PHP Push Array to Array  array_push() function using array in PHP
Java Programming using array
Java Programming using array  I'm creating a programming using array that will accept 10 letters and test if those letters are consonant... Program: import java.io.*; public class Array { public static void main(String args
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
array ADT
array ADT  Write a program using array_ADT to retrieve a list of elements from a file
array ADT
array ADT  Write a program using array_ADT to retrieve a list of elements from a file
Array of structure
Array of structure  create employment details with necessary field using array of structure
array string
array string  how to sort strings with out using any functions
array ADT
array ADT  Write a program using array_ADT to retrieve a list of URLs from a file. In your program take an array index as the input and delete the entry corresponding to that index
Java array
Java array  Java program to find first two maximum numbers in an array,using single loop without sorting array
use strings as array indexes using JavaScript
use strings as array indexes using JavaScript  How to use strings as array indexes using JavaScript
create a string from an array using JavaScript
create a string from an array using JavaScript  How to use "join()" to create a string from an array using JavaScript
example to booking ticket cinema using array
example to booking ticket cinema using array   example to booking ticket cinema using array
array list
array list  How to get repeate occurence values from database table in java by using arraylist
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
Queue implementation using array.
Description: In this tutorial you will see how to implement queue using array and queue insert & delete operations. Code: #include <stdio.h> #define MAX 5 #include <stdlib.h> void insert(int queue[], int *rear
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
Sorting the array
candidates in a talent contest. The program should use a String array to hold the names of the 5 candidates and an integer array to record the number of votes for each... : //exam result processing - using selection sort import java.util.*; public class
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
php array loop count
php array loop count  Count the array using loop in php
php array loop while
php array loop while  Using the php array while loop
Array List
Array List   Complete the class House and HouseApp below to display...?¬â?˘ information using the following format // // HOUSE IN TAMAN... ArrayList. Display the housesââ?¬â?˘ information using the following format
Array List
Array List  Could somebody help me to solve this question. I am glad... the housesâ?? information using the following format // // HOUSE IN TAMAN... the housesâ?? information using the following format: // HOUSE IN TAMAN ILMU LESS
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
Array Sizeof Function PHP
Array Sizeof Function PHP  Hi, How to count the number of elements in an array using the PHP Array sizeof() function? Please provides me online help links or example of array sizedof() PHP. Thanks
php array length for loop
php array length for loop  can i get the php array length using for loop
array_merge null - PHP
array_merge null   i am using the array_merge and getting the unusual null error...any help
array, index, string
array, index, string  how can i make dictionary using array...please help
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
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
Multiply a range of array elements using Recursion
Multiply a range of array elements using Recursion In this section you will learn how to use recursion to multiply a range of array elements. For this we have created a method rangeMult() that takes three arguments: an int array
Array example
to understand an Array example, For this we are using Java Scripting language... Array example       Array is an object that hold the data of similar type. The length

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.