Skip to content

Instantly share code, notes, and snippets.

@caidanw
Created December 11, 2019 03:08
Show Gist options
  • Save caidanw/de5b9edf17cac8041bd15750cee3b914 to your computer and use it in GitHub Desktop.
Save caidanw/de5b9edf17cac8041bd15750cee3b914 to your computer and use it in GitHub Desktop.
class LengthOfLastWord {
public static void main(String[] args) {
System.out.println(lengthOfLastWord("The longest word in any of the major English language dictionaries is pneumonoultramicroscopicsilicovolcanoconiosis"));
}
public static int lengthOfLastWord(String sentence) {
String[] words = sentence.split(" ", -1);
String lastWord = words[words.length - 1];
return lastWord.length();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment