question archive Coding Problem: Have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string

Coding Problem: Have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string

Subject:Computer SciencePrice: Bought3

Coding Problem:

Have the function LongestWord(sen) take the sen parameter being passed and return the largest word in the string. If there are two or more words that are the same length, return the first word from the string with that length. Ignore punctuation and assume sen will not be empty. Write a java method to solve this problem in O(n) time complexity, O(n) space complexity.

 

Examples: Input: "fun&!! Time"     Output: time 

             Input: "I love dogs"      Output: love

 

import java.util.*;

import java.io.*;

 

class longestword {  

 

  public static String LongestWord(String sen) {    

    // code goes here

}

  public static void main (String[] args) {    

     Scanner s = new Scanner(System.in);    

     System.out.print(LongestWord(s.nextLine()));

  }

}

pur-new-sol

Purchase A New Answer

Custom new solution created by our subject matter experts

GET A QUOTE