Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void printSix(@NotNull String input) {
- String newInput = input.replace(".", "");
- newInput = newInput.replace(":", "");
- String[] inputArray = newInput.split(" ");
- String longestWord = "";
- long longestWords = 0;
- for (String word : inputArray) {
- if (word.length() < longestWord.length()) {
- continue;
- }
- longestWord = word;
- longestWords = longestWords + 1;
- }
- if (longestWords != 1) {
- System.out.println("Error. Multiple long words found. Please try again.");
- } else {
- System.out.println(longestWord + ", Length: " + longestWord.length());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement