-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab4.java
More file actions
37 lines (37 loc) · 1.04 KB
/
Copy pathlab4.java
File metadata and controls
37 lines (37 loc) · 1.04 KB
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
37
import java.util.Scanner;
public class lab4
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int R = sc.nextInt(), C = sc.nextInt();
int matrix[][] = new int[R][C];
for(int row = 0; row < R; row++)
{
for(int col = 0; col < C; col++)
{
matrix[row][col] = sc.nextInt();
}
}
for(int col = 1; col < C; col++)
{
if(col % 2 != 0)
{
for(int row = 0, rev = R - 1; row < R / 2; row++, rev--)
{
int temp = matrix[row][col];
matrix[row][col] = matrix[rev][col];
matrix[rev][col] = temp;
}
}
}
for(int row = 0; row < R; row++)
{
for(int col = 0; col < C; col++)
{
System.out.print(matrix[row][col] + " ");
}
System.out.println();
}
}
}