Skip to main content
Commonmark migration
Source Link

#Way too complicated#

Way too complicated

Everything after the two isLetter() checks is extremely complicated and unnecessary. You can just subtract the two character values, like this:

public int getDistanceBetweenTwoLetters(char firstChar, char secondChar) throws AlphabetException {
    if(!isLetter(firstChar)){
        throw new AlphabetException(firstChar+" is not part of the alphabet");
    }
    if(!isLetter(secondChar)){
        throw new AlphabetException(secondChar+" is not part of the alphabet");
    }
    return Character.toLowerCase(secondChar) - Character.toLowerCase(firstChar);
}

#Way too complicated#

Everything after the two isLetter() checks is extremely complicated and unnecessary. You can just subtract the two character values, like this:

public int getDistanceBetweenTwoLetters(char firstChar, char secondChar) throws AlphabetException {
    if(!isLetter(firstChar)){
        throw new AlphabetException(firstChar+" is not part of the alphabet");
    }
    if(!isLetter(secondChar)){
        throw new AlphabetException(secondChar+" is not part of the alphabet");
    }
    return Character.toLowerCase(secondChar) - Character.toLowerCase(firstChar);
}

Way too complicated

Everything after the two isLetter() checks is extremely complicated and unnecessary. You can just subtract the two character values, like this:

public int getDistanceBetweenTwoLetters(char firstChar, char secondChar) throws AlphabetException {
    if(!isLetter(firstChar)){
        throw new AlphabetException(firstChar+" is not part of the alphabet");
    }
    if(!isLetter(secondChar)){
        throw new AlphabetException(secondChar+" is not part of the alphabet");
    }
    return Character.toLowerCase(secondChar) - Character.toLowerCase(firstChar);
}
Source Link
JS1
  • 28.6k
  • 3
  • 41
  • 83

#Way too complicated#

Everything after the two isLetter() checks is extremely complicated and unnecessary. You can just subtract the two character values, like this:

public int getDistanceBetweenTwoLetters(char firstChar, char secondChar) throws AlphabetException {
    if(!isLetter(firstChar)){
        throw new AlphabetException(firstChar+" is not part of the alphabet");
    }
    if(!isLetter(secondChar)){
        throw new AlphabetException(secondChar+" is not part of the alphabet");
    }
    return Character.toLowerCase(secondChar) - Character.toLowerCase(firstChar);
}