Professional Documents
Culture Documents
ARKAN NIKO SARAJIVA - Struktur Data
ARKAN NIKO SARAJIVA - Struktur Data
KELAS: F2
Answer :
a. Certainly! In Java, an array can be created using square brackets [] after the data type, like
this:
public class Main {
public static void main(String[] args) {
String[] devices = {"smartphone", "television", "computer"};
System.out.println(devices[0]);
System.out.println(devices[1]);
System.out.println(devices[2]);
}
}
This will create a String array named devices containing the three device types. You can access
the elements of the array using the index, like devices[0] for "smartphone", devices[1] for
"television", and so on.
b. System.out.println(devices[0]);
System.out.println(devices[1]);
System.out.println(devices[2]);
2. we have data for 4 days can be presented as a two dimensional array as below using java :
day 1 - 22 12 5 2
day 2 - 15 6 10 20
day 3 - 10 8 12 5
day 4 - 12 15 8 6
c.
days[1][2] Output: 10
d.
days[0]) Output: [22, 12, 5, 2]