Skip to content

Commit 8e783c7

Browse files
Update 18.1 Reverse Array.java
1 parent a7904d6 commit 8e783c7

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

18.1 Reverse Array.java

+43
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,46 @@ public static void main(String[] args) {
5050

5151
}
5252
}
53+
54+
// other solutions
55+
import java.io.*;
56+
57+
import java.util.*;
58+
59+
public class Solution {
60+
61+
public static void main(String[] args) {
62+
63+
Scanner sc = new Scanner(System.in);
64+
65+
int n = sc.nextInt();
66+
67+
if(n<=0){
68+
69+
return;
70+
71+
}
72+
73+
int[] ar = new int[n];
74+
75+
int i = 0;
76+
77+
while(sc.hasNextInt()){
78+
79+
ar[i] = sc.nextInt();
80+
81+
i++;
82+
83+
}
84+
85+
int m = i;
86+
87+
for(int j=m-1;j>=0;j--){
88+
89+
System.out.print(ar[j]+" ");
90+
91+
}
92+
93+
}
94+
95+
}

0 commit comments

Comments
 (0)