Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d8b06a3

Browse files
Rajat-Jain29Rajat
and
Rajat
authored
Add matrixTranspose.java (TheAlgorithms#2041)
Co-authored-by: Rajat <${GITHUB_ACTOR}@users.noreply.github.com>
1 parent 434320e commit d8b06a3

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

‎Code.html

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package Misc;
2+
import java.util.Scanner;
3+
/**
4+
*
5+
<h1>Find the Transpose of Matrix!</h1>
6+
Simply take input from the user and
7+
* print the matrix before the transpose and after the transpose.
8+
*
9+
<p>
10+
* <b>Note:</b> Giving proper comments in your program makes it more user
11+
* friendly and it is assumed as a high quality code.
12+
*
13+
* @author Rajat-Jain29
14+
* @version 11.0.9
15+
* @since 2014年03月31日
16+
*/
17+
public class matrixTranspose {
18+
public static void main(String[] args) {
19+
/*
20+
* This is the main method
21+
*
22+
* @param args Unused.
23+
*
24+
* @return Nothing.
25+
*/
26+
Scanner sc = new Scanner(System.in);
27+
int i, j, row, column;
28+
System.out.println("Enter the number of rows in the 2D matrix:");
29+
/*
30+
* Take input from user for how many rows to be print
31+
*/
32+
row = sc.nextInt();
33+
System.out.println("Enter the number of columns in the 2D matrix:");
34+
/*
35+
* Take input from user for how many coloumn to be print
36+
*/
37+
column = sc.nextInt();
38+
int[][] arr = new int[row][column];
39+
System.out.println("Enter the elements");
40+
for (i = 0; i < row; i++) {
41+
for (j = 0; j < column; j++) {
42+
arr[i][j] = sc.nextInt();
43+
}
44+
}
45+
/*
46+
* Print matrix before the Transpose in proper way
47+
*/
48+
System.out.println("The matrix is:");
49+
for (i = 0; i < row; i++) {
50+
for (j = 0; j < column; j++) {
51+
System.out.print(arr[i][j] + "\t");
52+
}
53+
System.out.print("\n");
54+
}
55+
/*
56+
* Print matrix after the tranpose in proper way Transpose means Interchanging
57+
* of rows wth column so we interchange the rows in next loop Thus at last
58+
* matrix of transpose is obtained through user input...
59+
*/
60+
System.out.println("The Transpose of the given matrix is:");
61+
for (i = 0; i < column; i++) {
62+
for (j = 0; j < row; j++) {
63+
System.out.print(arr[j][i] + "\t");
64+
}
65+
System.out.print("\n");
66+
}
67+
}
68+
}

‎DIRECTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@
173173

174174
## Misc
175175
* [ColorContrastRatio](https://github.com/TheAlgorithms/Java/blob/master/Misc/ColorContrastRatio.java)
176+
* [matrixTranspose](https://github.com/TheAlgorithms/Java/blob/master/Misc/matrixTranspose.java)
176177
* [MedianOfRunningArray](https://github.com/TheAlgorithms/Java/blob/master/Misc/MedianOfRunningArray.java)
177178
* [PalindromePrime](https://github.com/TheAlgorithms/Java/blob/master/Misc/PalindromePrime.java)
178179
* [RangeInSortedArray](https://github.com/TheAlgorithms/Java/blob/master/Misc/RangeInSortedArray.java)

‎Misc/matrixTranspose.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package Misc;
2+
3+
import java.util.Scanner;
4+
5+
/**
6+
* <h1>Find the Transpose of Matrix!</h1> Simply take input from the user and
7+
* print the matrix before the transpose and after the transpose.
8+
* <p>
9+
* <b>Note:</b> Giving proper comments in your program makes it more user
10+
* friendly and it is assumed as a high quality code.
11+
*
12+
* @author Rajat-Jain29
13+
* @version 11.0.9
14+
* @since 2014年03月31日
15+
*/
16+
17+
public class matrixTranspose {
18+
public static void main(String[] args) {
19+
/*
20+
* This is the main method
21+
*
22+
* @param args Unused.
23+
*
24+
* @return Nothing.
25+
*/
26+
Scanner sc = new Scanner(System.in);
27+
int i, j, row, column;
28+
System.out.println("Enter the number of rows in the 2D matrix:");
29+
30+
/*
31+
* Take input from user for how many rows to be print
32+
*/
33+
row = sc.nextInt();
34+
35+
System.out.println("Enter the number of columns in the 2D matrix:");
36+
37+
/*
38+
* Take input from user for how many coloumn to be print
39+
*/
40+
column = sc.nextInt();
41+
int[][] arr = new int[row][column];
42+
System.out.println("Enter the elements");
43+
for (i = 0; i < row; i++) {
44+
for (j = 0; j < column; j++) {
45+
arr[i][j] = sc.nextInt();
46+
}
47+
}
48+
49+
/*
50+
* Print matrix before the Transpose in proper way
51+
*/
52+
53+
System.out.println("The matrix is:");
54+
for (i = 0; i < row; i++) {
55+
for (j = 0; j < column; j++) {
56+
System.out.print(arr[i][j] + "\t");
57+
}
58+
System.out.print("\n");
59+
}
60+
61+
/*
62+
* Print matrix after the tranpose in proper way Transpose means Interchanging
63+
* of rows wth column so we interchange the rows in next loop Thus at last
64+
* matrix of transpose is obtained through user input...
65+
*/
66+
67+
System.out.println("The Transpose of the given matrix is:");
68+
for (i = 0; i < column; i++) {
69+
for (j = 0; j < row; j++) {
70+
System.out.print(arr[j][i] + "\t");
71+
}
72+
System.out.print("\n");
73+
}
74+
}
75+
76+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /