1/* 2 * RemoveCapitals.java3 * 4 * Computer Science S-225 */6 7/**8 * Removing capital (upper case) letters from a string9 */10public class RemoveCapitals {11 12 /*13 * removeCapitals("HeLLo") calls removeCapitals("eLLo")14 * removeCapitals("eLLo") calls removeCapitals("LLo")15 * removeCapitals("LLo") calls removeCapitals("Lo")16 * removeCapitals("Lo") calls removeCapitals("o")17 * removeCapitals("o") calls removeCapitals("")18 * removeCapitals("") returns ""19 * removeCapitals("o") returns "o" + "" -> "o"20 * removeCapitals("Lo") returns "o"21 * removeCapitals("LLo") returns "o"22 * removeCapitals("eLLo") returns "eo"23 * removeCapitals("HeLLo") returns "eo"24 */25 public static String removeCapitals(String str) {26 if (str.equals("")) {27 return str;28 }29 30 String rest = removeCapitals(str.substring(1));31 char first = str.charAt(0);32 33 if (Character.isUpperCase(first)) {34 return rest;35 } else {36 return first + rest;37 }38 }39 40 public static void main(String[] args) {41 String input = "HeLLo";42 if (args.length > 0) {43 input = args[0];44 }45 46 System.out.println(removeCapitals(input));47 }48}