Skip to content

Commit 7679d0c

Browse files
authored
Add files via upload
1 parent 8999ca5 commit 7679d0c

File tree

1 file changed

+145
-0
lines changed

1 file changed

+145
-0
lines changed

2D Arrays/transpose.java

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
Title : Find the transpose of the matrix .
3+
*/
4+
import java.util.Scanner;
5+
import java.lang.*;
6+
class transpose
7+
{
8+
final static int MAXLIMIT=10 ;
9+
private int row;
10+
private int col;
11+
int i ,j ;
12+
private double a[][];
13+
14+
transpose(int rows , int cols) //Constructor
15+
{
16+
row=rows ;
17+
col=cols ;
18+
a=new double[row][col] ;
19+
20+
}
21+
22+
Scanner in=new Scanner(System.in);
23+
24+
public void get ()
25+
{
26+
System.out.println("\n Enter the elements : \n");
27+
for(i=0;i<row;i++)
28+
{
29+
for(j=0;j<col;j++)
30+
{
31+
a[i][j]=in.nextDouble();
32+
}
33+
}
34+
35+
}
36+
37+
public void display ()
38+
{
39+
System.out.println( "\n Matrix A " + row + " * " + col + " : \n") ;
40+
41+
for(i=0;i<row;i++)
42+
{
43+
for(j=0;j<col;j++)
44+
{
45+
System.out.print(a[i][j]+ "\t") ;
46+
}
47+
System.out.println("\n") ;
48+
}
49+
}
50+
51+
public void trans()
52+
{
53+
System.out.println( "\n\n The transpose of the given matrix : \n");
54+
System.out.println( "\n Matrix AT " + col + " * " + row+ " : \n") ;
55+
56+
for(i=0;i<col;i++)
57+
{
58+
for(j=0;j<row;j++)
59+
{
60+
System.out.print(a[j][i]+ "\t") ;
61+
}
62+
System.out.println("\n") ;
63+
}
64+
}
65+
66+
public static void main (String [] args )
67+
{
68+
int rows , cols ;
69+
int opt;
70+
Scanner in=new Scanner(System.in);
71+
do
72+
{ opt=0;
73+
System.out.println("\n Enter the total number of rows and columns respectively : \n");
74+
rows=in.nextInt();
75+
cols=in.nextInt();
76+
if(rows>MAXLIMIT|| cols>MAXLIMIT|| rows<1||cols<1)
77+
{
78+
System.out.println("\n Invalid enteries ! \n Remember , Maximum limit of rows and columns is 10 .\n");
79+
System.out.println(" Do you wish to continue ? \n Press 1 if yes otherwise any to stop . \n");
80+
opt=in.nextInt();
81+
}
82+
83+
else
84+
{
85+
86+
transpose A = new transpose(rows , cols);
87+
A.get();
88+
A.display();
89+
A.trans();
90+
91+
92+
}
93+
} while(opt==1);
94+
95+
}
96+
97+
}
98+
99+
/*
100+
101+
Enter the total number of rows and columns respectively :
102+
103+
13
104+
1
105+
106+
Invalid enteries !
107+
Remember , Maximum limit of rows and columns is 10 .
108+
109+
Do you wish to continue ?
110+
Press 1 if yes otherwise any to stop .
111+
112+
1
113+
114+
Enter the total number of rows and columns respectively :
115+
116+
3
117+
2
118+
119+
Enter the elements :
120+
121+
1
122+
2
123+
3
124+
5
125+
5
126+
5
127+
128+
Matrix A 3 * 2 :
129+
130+
1.0 2.0
131+
132+
3.0 5.0
133+
134+
5.0 5.0
135+
136+
137+
The transpose of the given matrix : \n");
138+
139+
Matrix AT 2 * 3 :
140+
141+
1.0 3.0 5.0
142+
143+
2.0 5.0 5.0
144+
145+
*/

0 commit comments

Comments
 (0)