We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 61138e0 commit 638f2d6Copy full SHA for 638f2d6
1 file changed
TestArray.java
@@ -1,13 +1,29 @@
1
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
17
public static void main (String[] args) {
18
int a1 = 3;
19
int a2 = 5;
20
int a3 = 7;
21
int[] arr = {a1, a2, a3};
22
- for (int a : arr)
- {
- System.out.println(a);
- }
23
+ System.out.println("Array length = " + arr.length);
24
+ printArray(arr);
25
26
+ int[] arr2 = returnArray(2, 4, 6);
27
+ printArray(arr2);
28
}
29
0 commit comments