https://pastein.ru/t/ll

  скопируйте уникальную ссылку для отправки


public class Start {
    public static void main(String[] args) {
        getLongestWord("i'm gonna make a change for once in my life it's gonna feel real good gonna make a difference");
        getLongestWord("Every night in my dreams i see you i feel you that is how i know you go on far across the distance and spaces between us you have come to show you go on");
    }   
    
    private static String getLongestWord(String phrase){
        String words[] = phrase.split(" ");
        Arrays.sort(words);
        
        int len = 0;
        String longest = "";
        
        for (String string : words) {
            if (string.length() > len) {
                len = string.length();
                longest = string;
            }
        }
        
        System.out.println("The longest word is: " + longest);
        
        return longest;
    }
}
1
10.07.2019, 20:36