Output: ABCD, ACBD, ACDB, CABD, CADB, CDAB
public static void interleave(String ab, String cd, String str) { if(ab.length() == 0) { str += cd; System.out.println(str); return; } interleave(ab.substring(1), cd, str + ab.charAt(0)); interleave(cd.substring(1), ab, str + cd.charAt(0)); }