Skip to content

Instantly share code, notes, and snippets.

@tonkatsu7
Last active July 12, 2018 14:09
Show Gist options
  • Save tonkatsu7/8ab57e9c712501714c711b88dcdfadfb to your computer and use it in GitHub Desktop.
Save tonkatsu7/8ab57e9c712501714c711b88dcdfadfb to your computer and use it in GitHub Desktop.
CoderByte challenge Longest Word
import java.util.*;
import java.io.*;
class Main {
public static String LongestWord(String sen) {
String[] words = sen.split("\\W");
String longest = "";
for (String word : words)
longest = word.length() > longest.length() ? word : longest;
return longest;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(LongestWord(s.nextLine()));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment