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 cccb7be

Browse files
github-actionsgithub-actions
github-actions
authored and
github-actions
committed
Formatted with Google Java Formatter
1 parent d8b06a3 commit cccb7be

File tree

1 file changed

+59
-57
lines changed

1 file changed

+59
-57
lines changed

‎Misc/matrixTranspose.java‎

Lines changed: 59 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,76 @@
33
import java.util.Scanner;
44

55
/**
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.
6+
*
7+
*
8+
* <h1>Find the Transpose of Matrix!</h1>
9+
*
10+
* Simply take input from the user and print the matrix before the transpose and after the
11+
* transpose.
12+
*
13+
* <p><b>Note:</b> Giving proper comments in your program makes it more user friendly and it is
14+
* assumed as a high quality code.
1115
*
1216
* @author Rajat-Jain29
1317
* @version 11.0.9
1418
* @since 2014年03月31日
1519
*/
16-
1720
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();
21+
public static void main(String[] args) {
22+
/*
23+
* This is the main method
24+
*
25+
* @param args Unused.
26+
*
27+
* @return Nothing.
28+
*/
29+
Scanner sc = new Scanner(System.in);
30+
int i, j, row, column;
31+
System.out.println("Enter the number of rows in the 2D matrix:");
3432

35-
System.out.println("Enter the number of columns in the 2D matrix:");
33+
/*
34+
* Take input from user for how many rows to be print
35+
*/
36+
row = sc.nextInt();
3637

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-
}
38+
System.out.println("Enter the number of columns in the 2D matrix:");
4839

49-
/*
50-
* Print matrix before the Transpose in proper way
51-
*/
40+
/*
41+
* Take input from user for how many coloumn to be print
42+
*/
43+
column = sc.nextInt();
44+
int[][] arr = new int[row][column];
45+
System.out.println("Enter the elements");
46+
for (i = 0; i < row; i++) {
47+
for (j = 0; j < column; j++) {
48+
arr[i][j] = sc.nextInt();
49+
}
50+
}
5251

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-
}
52+
/*
53+
* Print matrix before the Transpose in proper way
54+
*/
6055

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-
*/
56+
System.out.println("The matrix is:");
57+
for (i = 0; i < row; i++) {
58+
for (j = 0; j < column; j++) {
59+
System.out.print(arr[i][j] + "\t");
60+
}
61+
System.out.print("\n");
62+
}
6663

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-
}
64+
/*
65+
* Print matrix after the tranpose in proper way Transpose means Interchanging
66+
* of rows wth column so we interchange the rows in next loop Thus at last
67+
* matrix of transpose is obtained through user input...
68+
*/
7569

70+
System.out.println("The Transpose of the given matrix is:");
71+
for (i = 0; i < column; i++) {
72+
for (j = 0; j < row; j++) {
73+
System.out.print(arr[j][i] + "\t");
74+
}
75+
System.out.print("\n");
76+
}
77+
}
7678
}

0 commit comments

Comments
(0)

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