I am trying to write a basic javascript function to find the longest word in a string and log it\'s length.
So far I have:
function findLongestWord(
To find the longest keyword string in Java you need to write a program.
public class FindLarge {
private String longestWord;
public String longestWord(String sen) {
String arr[] = sen.split(" "); // seperates each word in the string and stores it in array
longestWord = arr[0]; // Assume first word to be the largest word
for (String a : arr)
if (longestWord.length() < a.length()) // check length of each word
longestWord = a;
return longestWord;
}
public static void main(String[] args) {
FindLarge fl=new FindLarge();
String longestWord=fl.longestWord("Hello Welcome to Java"); // string to be checked
System.out.println("Longest Word: "+ longestWord); // Final Output
}