diff --git a/Contributors.md b/Contributors.md index 7684c46..64447eb 100644 --- a/Contributors.md +++ b/Contributors.md @@ -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) \ No newline at end of file diff --git a/array/reverse an array/java/reverse.java b/array/reverse an array/java/reverse.java new file mode 100644 index 0000000..cd35feb --- /dev/null +++ b/array/reverse an array/java/reverse.java @@ -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); + } + +}