Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132930 views
License: OTHER
1
public class QuizArray {
2
private static String[] deepCopy(String[] original) {
3
String[] copy = new String[original.length];
4
for (int i = 0; i < original.length; i++) {
5
copy[i] = original[i];
6
}
7
return copy;
8
}
9
10
public static void main(String[] args) {
11
String[] myArray1 = { " geh ", "du", "alter", "esel" };
12
String[] myArray2 = deepCopy(myArray1);
13
myArray2[3] = "sack";
14
15
System.out.print("myArray1: ");
16
for (int i = 0; i < myArray1.length; i++) {
17
System.out.print(myArray1[i] + " ");
18
}
19
20
System.out.print("\nmyArray2: ");
21
for (int i = 0; i < myArray2.length; i++) {
22
System.out.print(myArray2[i] + " ");
23
}
24
}
25
}
26
27