Write a program in java using two dimensional arrays. You should prompt the user
ID: 3640622 • Letter: W
Question
Write a program in java using two dimensional arrays. You should prompt the user toenter the number of rows and columns for your matrix. You should then prompt the user
to enter values for each element of the matrix. Once the user has provided all the values for matrix, you should print the matrix and transpose of that matrix. A transpose of a matrix converts rows to columns and columns to rows.
Example:
Output: This program transposes a matrix.
Output: Please enter the number of rows:
User enters 2
Output: Please enter the number of columns:
User enters 3
Enter value for row[0] column[0]: 9
Enter value for row[0] column[1]: 1
Enter value for row[0] column[2]: 2
Enter value for row[1] column[0]: 72
Enter value for row[1] column[1]: 3
Enter value for row[1] column[2]: 6
The matrix you entered is:
9 1 2
72 3 6
The transpose of this matrix has 3 rows and 2 columns and the transpose is:
9 72
1 3
2 6
Explanation / Answer
This program should do exactly what you wanted. Link: - http://dl.dropbox.com/u/28713122/Cramster/Traverse2D.java --------------------------------- Source Code: import java.util.Scanner; public class Traverse2D { public static void main(String[] args) { Scanner input = new Scanner(System.in); int rows, columns; System.out.println("This program transposes a matrix."); System.out.print("Please enter the number of rows: "); rows = input.nextInt(); System.out.print("Please enter the number of columns: "); columns = input.nextInt(); int[][] matrix = new int[rows][columns]; int[][] tmatrix = new int[columns][rows]; for(int i = 0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.