What is the output of the following?
1: public class Main { 2: public static void main(String[] args) { 3: StringBuilder sb = new StringBuilder(); 4: sb.append("red"); 5: sb.deleteCharAt(0); 6: sb.delete(1, 1); 7: System.out.println(sb); 8: } 9: }
C.
Line 3 creates an empty StringBuilder.
Line 4 adds three characters to it.
Line 5 removes the first character resulting in ed.
Line 6 deletes the characters starting at position 1 and ending right before position 1.
Since there are no indexes that meet that description, the line has no effect. Therefore, Option C is correct.