import java.io.*;
class longest_word
{
public static void longest( ) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the string ");
String str=br.readLine();
str=str.trim();
str=str+" ";
int l = str.length();
String max="",temp=" ";
int maxl=0,tl=0 ,p=0;
for (int i=0;i<l;i++)
{
if(str.charAt(i)==32)
{
temp=str.substring(p,i);
tl=temp.length();
if( tl > maxl )
max=temp;
maxl=tl;
p=i+1;
}
}
System.out.println("the longest word is"+max);
System.out.println("the lenght of the longest word is"+maxl);
}
}
class longest_word
{
public static void longest( ) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the string ");
String str=br.readLine();
str=str.trim();
str=str+" ";
int l = str.length();
String max="",temp=" ";
int maxl=0,tl=0 ,p=0;
for (int i=0;i<l;i++)
{
if(str.charAt(i)==32)
{
temp=str.substring(p,i);
tl=temp.length();
if( tl > maxl )
max=temp;
maxl=tl;
p=i+1;
}
}
System.out.println("the longest word is"+max);
System.out.println("the lenght of the longest word is"+maxl);
}
}
No comments:
Post a Comment