Quiz 4
Question 1
Write out the Java syntax to declare a new array of length 100 to hold strings.
Answer
String[] myArray = new String[100];
Question 2
Fix the following code so that it will correctly check whether two strings contain the same characters.
String a = "beep"
String b = "beep"
if (a == b) { // uh oh, this won't work
System.out.println("Same word.");
}
Answer
String a = "beep"
String b = "beep"
if (a.equals(b)) { // uh oh, this won't work
System.out.println("Same word.");
}
Question 3
Explain in a few sentences what a reference is as it relates to arrays. Feel free to draw a diagram or use analogies if that would be helpful (but it’s not necessary).