Ad
Regular Expressions
Declarative Programming
Advanced Language Features
Programming Paradigms
Fundamentals
Strings

How easy is it to master even-and-odd-ology from a strong foundation of knowledge about obscure numeral systems?

Code
Diff
  • class StringParity {
      public static String parityName(int n) {
        return Character.getName('౼' - n % 2).split(" ")[5];
      }
      
      public static boolean isEvenLength(String str) {
        return parityName(str.length()).equals("EVEN");
      }
      
      public static boolean isOddLength(String str) {
        return parityName(str.length()).equals("ODD");
      }
    }
    • class StringParity {
    • public static String parityName(int n) {
    • return Character.getName('౼' - n % 2).split(" ")[5];
    • }
    • public static boolean isEvenLength(String str) {
    • return str.replaceAll("(?s)..", "").isEmpty(); // (?s) enables DOTALL
    • return parityName(str.length()).equals("EVEN");
    • }
    • public static boolean isOddLength(String str) {
    • return parityName(str.length()).equals("ODD");
    • }
    • }