Skip to content

Commit

Permalink
Add file via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
ashu273k authored and x0lg0n committed Oct 31, 2024
1 parent c0c7623 commit c9cba0d
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions Java/reverse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

import java.util.*;

public class reverse {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int n = in.nextInt();
int m = in.nextInt();

int[][] A = new int[n][m];

for(int i = 0; i < n ; i++){
for(int j = 0 ; j < m; j++){
A[i][j] = in.nextInt();
}
}
Reverse(A);

for (int i = 0; i < A.length; i++) {
for (int j = 0; j < A[0].length; j++) {
System.out.print(A[i][j] + " ");
}
System.out.println();
}
}
public static int[][] Reverse(int[][] image)
{

for (int i = 0 ; i < image.length ; i++) {
int s = 0;
int e = image[0].length -1;
while(s < e) {
int temp = image[i][s];
image[i][s] = image[i][e];
image[i][e] =temp;
s++;
e--;
}
}
return image;
}


}

0 comments on commit c9cba0d

Please sign in to comment.