• TheLazyNerd@europe.pub
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      6 hours ago

      I’m not too good with java, but it should be something like this:

      public static int convertRomanNumeral(string n){Map.of("M","DD","CD","CCCC","D","CCCCC","C","LL","XL","XXXX","L","XXXXX","X","VV","IV","IIII","V","IIIII");.forEach((k,v)->{n=n.replace(k,v);});return n.length();}

    • grue@lemmy.world
      link
      fedilink
      arrow-up
      25
      ·
      edit-2
      16 hours ago

      Code gulf, you say?

      public static String
      convertRomanNumeral(String numeral) {
          numeral = numeral.replace("America", "Mexico");
          return numeral;
      } 
      
    • ray@sh.itjust.works
      link
      fedilink
      arrow-up
      2
      ·
      14 hours ago
      public static int convertRomanNumeral(String numeral)
      {
        numeral = numeral.replace("M", "DD")
          .replace("CD", "CCCC")
          .replace("D", "CCCCC")
          .replace("C", "LL")
          .replace("XL", "XXXX")
          .replace("L", "XXXXX")
          .replace("X", "VV")
          .replace("IV", "IIII")
          .replace("V", "IIIII");
        return numeral.length();
      }
      
      • qaz@lemmy.worldOP
        link
        fedilink
        English
        arrow-up
        6
        ·
        10 hours ago
        public static int convertRomanNumeral(String numeral)
        {
          return numeral.replace("M", "DD")
            .replace("CD", "CCCC")
            .replace("D", "CCCCC")
            .replace("C", "LL")
            .replace("XL", "XXXX")
            .replace("L", "XXXXX")
            .replace("X", "VV")
            .replace("IV", "IIII")
            .replace("V", "IIIII")
            .length();
        }