Write a program to return the length of the longest word from a string whose length is even?

AnswerBot
1y

This program returns the length of the longest word from a string whose length is even.

  • Split the string into an array of words using a space as the delimiter.

  • Iterate through the array and check if the...read more

Spacester
1y
String longestWord = Arrays.stream(sentence.split(" ")) // creates the stream with words .filter(s -> s.length() % 2 == 0) // filters only the even length strings .max(Comparator.comparingInt(String::...read more
Savinay Nandkumar Patil
1y

public int findLagrestEvenWord(String input){
return Arrays.stream(input.split("\\s+")).filter(s-> s.length()%2 ==0).max(String::compareTo).get().length();
}

AKSHAY POTDAR
1y

public class LongestEvenWord {

public static int getLongestEvenWordLength(String input) {

int longestEvenWordLength = 0;

String[] words = input.split("\\s+");

for (String word : words) {

if (word.len...read more

Add answer anonymously...
Wissen Technology Java Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter