Skip to content

Commit 638f2d6

Browse files
committed
Modify TestArray
1 parent 61138e0 commit 638f2d6

1 file changed

Lines changed: 20 additions & 4 deletions

File tree

TestArray.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
public class TestArray {
2+
3+
private static int[] returnArray(int a, int b, int c) {
4+
// Using {a, b, c} only won't work!
5+
return new int[]{a, b, c};
6+
}
7+
8+
// Using Enhanced For-Loops
9+
private static void printArray(int[] array) {
10+
System.out.print("Array content: ");
11+
for (int i : array) {
12+
System.out.print(i + " ");
13+
}
14+
System.out.println("");
15+
}
16+
217
public static void main (String[] args) {
318
int a1 = 3;
419
int a2 = 5;
520
int a3 = 7;
621
int[] arr = {a1, a2, a3};
722

8-
for (int a : arr)
9-
{
10-
System.out.println(a);
11-
}
23+
System.out.println("Array length = " + arr.length);
24+
printArray(arr);
25+
26+
int[] arr2 = returnArray(2, 4, 6);
27+
printArray(arr2);
1228
}
1329
}

0 commit comments

Comments
 (0)