Created
December 11, 2019 03:08
-
-
Save caidanw/de5b9edf17cac8041bd15750cee3b914 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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