Q)...find the max length-word in
a given string and return the max-length word. if two words are of same length
return the first occuring word of max-length
input:"hello how are you aaaaa"
output:hello(length-5)
input:"hello how are you aaaaa"
output:hello(length-5)
- package Set1;
 - import java.util.*;
 - public class ClassSet14 {
 - public static String lengthiestString(String s1){
 - int max=0;
 - String s2=null;
 - StringTokenizer t=new StringTokenizer(s1," ");
 - while(t.hasMoreTokens()){
 - s1=t.nextToken();
 - int n=s1.length();
 - if(n>max){
 - max=n;
 - s2=s1; }
 - }
 - return s2;
 - }
 - public static void main(String[] args) {
 - Scanner s=new Scanner(System.in);
 - System.out.println("enter the String:");
 - String s1=s.nextLine();
 - System.out.println("the lengthiest string is:"+lengthiestString(s1));
 - }
 - }