Skip to content

Instantly share code, notes, and snippets.

@ramonaharrison
Created November 15, 2015 15:39
Show Gist options
  • Save ramonaharrison/060c425882857c1f015b to your computer and use it in GitHub Desktop.
Save ramonaharrison/060c425882857c1f015b to your computer and use it in GitHub Desktop.
Recursion HW 11/6
package nyc.c4q.ramonaharrison;
/**
* Access Code 2.1
* Ramona Harrison
* recursion.java
*/
public class Recursion {
public static void main(String[] args) {
System.out.println(isEvenWord("appeases"));
System.out.println(isEvenWord("banana"));
System.out.println(isEvenWord("cat"));
System.out.println(isEvenWord("tattletale"));
}
public static boolean isEvenWord(String word) {
if (word.isEmpty()) {
return true;
} else if (word.substring(1).contains(String.valueOf(word.charAt(0)))) {
return isEvenWord(word.substring(1).replaceFirst(String.valueOf(word.charAt(0)), ""));
} else {
return false;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment