-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathDeeperDiveArrays.java
44 lines (38 loc) Β· 1.08 KB
/
DeeperDiveArrays.java
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
package day4;
public class DeeperDiveArrays {
/*
time complexity: O(1)
space complexity: O(1)
*/
public static void main(String[] args) {
int[] array = new int[10];
double[] a = new double[45];
char[] characters = new char[7];
float[] precisonNumbers = new float[100];
String[] messages = {"hello", "world", "yeahhh"};
int[] numbers = {2, 3, 5, 7, 11, 13};
// array[5];
// starting address + index * 4 bytes
System.out.println(array[3]);
print(numbers);
print(messages);
}
/*
time complexity: O(n)
space complexity: O(1)
*/
private static void print(int[] array) {
for (int index = 0 ; index < array.length ; index++) {
System.out.print(array[index] + " ");
}
}
/*
time complexity: O(n)
space complexity: O(1)
*/
private static void print(String[] array) {
for (int index = 0 ; index < array.length ; index++) {
System.out.print(array[index] + " ");
}
}
}