Skip to content

Commit ec7b49a

Browse files
authored
Create PassingArray.java
1 parent abea0e3 commit ec7b49a

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

arrays/PassingArray.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.zetcode;
2+
3+
import java.util.Arrays;
4+
5+
public class PassingArray {
6+
7+
public static void main(String[] args) {
8+
9+
int[] a = { 3, 4, 5, 6, 7 };
10+
int[] r = reverseArray(a);
11+
12+
System.out.println(Arrays.toString(a));
13+
System.out.println(Arrays.toString(r));
14+
}
15+
16+
private static int[] reverseArray(int[] b) {
17+
18+
int[] c = new int[b.length];
19+
20+
for (int i=b.length-1, j=0; i>=0; i--, j++) {
21+
22+
c[j] = b[i];
23+
}
24+
25+
return c;
26+
}
27+
}

0 commit comments

Comments
 (0)