What is the result of the following code?
4: int total = 0; 5: StringBuilder letters = new StringBuilder("abcdefg"); 6: total += letters.substring(1, 2).length(); 7: total += letters.substring(6, 6).length(); 8: total += letters.substring(6, 5).length(); 9: System.out.println(total);
E.
Line 6 adds 1 to total because substring()
includes the starting index but not the ending index.
Line 7 adds 0 to total.
For Line 8: Java does not allow the indexes to be specified in reverse order and the code throws a StringIndexOutOfBoundsException.