public class MidtermReview { public static void main(String[] args) { System.out.println(undouble("bookkeeper")); } public static String undouble(String s) { // Fixed bug: Handles string of length 1 if (s.length() < 2) { return s; } else { char c1 = s.charAt(0); char c2 = s.charAt(1); if (c1 == c2) { return c1 + undouble(s.substring(2)); } else { // Fixed bug: Handles a string like "books" return c1 + undouble(s.substring(1)); } } } // Buggy Version public String buggyUndouble(String s) { if (s.isEmpty()) { // Bug: Wrong base case return s; } else { char c1 = s.charAt(0); char c2 = s.charAt(1); if (c1 == c2) { return c1 + undouble(s.substring(2)); } else { // Minor bug: c1 + c2 would run first which gives unexpected result // Bug: Doesn't work for "books" return c1 + c2 + undouble(s.substring(2)); } } } }