Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ Welcome to the list of people who contributed to this repo 💥
5. [iamprofessor1](https://github.com/iamprofessor1)(Added Kth largest leetcode in cpp)
6. [dcod3r](https://github.com/dcod3r)
7. [Ayansh](https://github.com/badasschef)
8. [Deep](https://github.com/deep846)
9. [Amit](https://github.com/amitShindeGit)
8. [Saransh](https://github.com/saranshkotnala)
9. [Deep](https://github.com/deep846)
10. [Amit](https://github.com/amitShindeGit)
41 changes: 41 additions & 0 deletions array/reverse an array/java/reverse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import java.io.*;
import java.util.*;

public class Main{
public static void display(int[] a){
StringBuilder sb = new StringBuilder();

for(int val: a){
sb.append(val + " ");
}
System.out.println(sb);
}

public static void reverse(int[] a){
int li = 0;
int ri = a.length - 1;

while(li < ri){
int temp = a[li];
a[li]= a[ri];
a[ri] = temp;

li++;
ri--;
}
}

public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

int n = Integer.parseInt(br.readLine());
int[] a = new int[n];
for(int i = 0; i < n; i++){
a[i] = Integer.parseInt(br.readLine());
}

reverse(a);
display(a);
}

}