-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArrayTranspose.java
36 lines (34 loc) · 1019 Bytes
/
ArrayTranspose.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* running for only n*n matrix.
*this code is also for rotation of array in right side.
*/
import java.util.Arrays;
public class ArrayTranspose
{
public static void main(String[] args)
{
int[][] matrix = {{1,2,3},
{5,6,7},
{9,10,11}};
transpose(matrix) ;
System.out.print("Modified matrix is \n");
for (int i = 0; i < matrix.length; i++)
{
for (int j = 0; j < matrix.length; j++)
System.out.print(matrix[i][j] + " ");
System.out.print("\n");
}
}
public static void transpose(int[][] matrix)
{
for (int row = 0; row < matrix.length; row++)
{
for (int column = row+1; column < matrix.length; column++)
{
matrix[row][column]^=matrix[column][row] ;
matrix[column][row]^=matrix[row][column] ;
matrix[row][column]^=matrix[column][row] ;
}
}
}
}