-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray.java
More file actions
35 lines (23 loc) · 790 Bytes
/
array.java
File metadata and controls
35 lines (23 loc) · 790 Bytes
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
public class array {
public static void main(String[] args) {
String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};
cars[0] = "Opel";
System.out.println(cars.length);
String[] carss = {"Volvo", "BMW", "Ford", "Mazda"};
for (int i = 0; i < carss.length; i++) {
System.out.println(carss[i]);
}
// array for each
for (String i : carss) {
System.out.println(i);
}
// two dimesnsional arrays
int[][] myNumbers = { {1, 2, 3, 4}, {5, 6, 7} };
System.out.println(myNumbers[1][2]); // Outputs 7
for (int i = 0; i < myNumbers.length; ++i) {
for(int j = 0; j < myNumbers[i].length; ++j) {
System.out.println(myNumbers[i][j]);
}
}
}
}