|
3 | 3 | import java.util.Scanner;
|
4 | 4 |
|
5 | 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. |
| 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. |
11 | 15 | *
|
12 | 16 | * @author Rajat-Jain29
|
13 | 17 | * @version 11.0.9
|
14 | 18 | * @since 2014年03月31日
|
15 | 19 | */
|
16 | | - |
17 | 20 | 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:"); |
34 | 32 |
|
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(); |
36 | 37 |
|
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:"); |
48 | 39 |
|
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 | + } |
52 | 51 |
|
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 | + */ |
60 | 55 |
|
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 | + } |
66 | 63 |
|
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 | + */ |
75 | 69 |
|
| 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 | + } |
76 | 78 | }
|
0 commit comments