Java ICSE Class 10 :
Enter a string in java and print the largest word in it and count it's letters.
Answers
Answered by
0
Answer:
// Java program to find the number of charters
// in the longest word in the sentence.
class GFG {
static int LongestWordLength(String str)
{
String[] words = str.split(" ");
int length = 0;
for(String word:words){
if(length < word.length()){
length = word.length();
}
}
return length;
}
// Driver code
public static void main(String args[])
{
String str = "I am an intern at binscomputer.com";
System.out.println(LongestWordLength(str));
}
}
Output:
15
Explanation:
Similar questions