Question 1 of 5
Consider:
String s = "fir";
String t = s + "th";
(a) Give s and t. (b) Explain whether s is mutated in place. (c) Explain what + does here.
Responses receive AI feedback against a rubric after submission. Scores are practice estimates.
Consider:
String s = "fir";
String t = s + "th";
(a) Give s and t. (b) Explain whether s is mutated in place. (c) Explain what + does here.
SlipMark.toString is supplied.
class SlipMark {
private int number;
public SlipMark(int n) {
number = n;
}
public String toString() {
return "slip-" + number;
}
}
SlipMark m = new SlipMark(3);
System.out.print(1 + 4 + "" + m);
(a) Give the displayed text. (b) Explain 1 + 4 in this expression. (c) Explain the role of toString.
Let w be "willow".
| Call | Your result |
|---|---|
| w.substring(1, 4) | |
| w.substring(2, 2) | |
| w.indexOf("ll") |
Fill the table and explain why substring(2, 2) is legal.
Indexing versus substring bounds: let word be "ketch" and let n be word.length().
(a) Give the valid character indexes of ketch. (b) Give word.substring(0, n). (c) Explain why word.substring(n) is empty while a character index of n would be invalid.
Use equals and compareTo on strings.
(a) Give "harbor".equals("harbor") and "harbor".equals("Harbor"). (b) State the sign of "ketch".compareTo("glen"). (c) Explain why a student should not claim the compareTo result must be 4 or any other fixed nonzero number.