forked from LaunchCodeEducation/java-exercises
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrays.java
More file actions
49 lines (34 loc) · 1.17 KB
/
Copy pathArrays.java
File metadata and controls
49 lines (34 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package org.launchcode.java.demos;
/**
* Created by LaunchCode
*/
public class Arrays {
public static void main(String[] args) {
System.out.println("printArrayOfNumbers :: ");
printArrayOfNumbers();
System.out.println("arrayCreation :: ");
arrayCreation();
}
public static void printArrayOfNumbers() {
// Declare and initialize an array of integers
int[] numbers = {1, 2, 6, 9, 10, 14, 17, 20, 24, 42, 45, 85};
// Loop over the array and print each number
for (int i = 0; i < numbers.length; i++) {
System.out.println(numbers[i]);
}
}
public static void arrayCreation() {
// Declare and initialize an empty array of 10 Integers
int[] someInts = new int[10];
// Declare and initialize an array using an array literal
int[] someOtherInts = {1, 1, 2, 3, 5, 8};
// We can use a for-in loop with arrays
for (int i : someInts) {
System.out.println(i);
}
// We can loop through an array with an iterator var as well
for (int j : someOtherInts) {
System.out.println(j);
}
}
}