class LongestWord
{
public static void main(String args[])throws IOException
{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String");
String s=in.readLine();
int l=s.length();
String wo="",w="";
s=s+" ";
int max=0,x;
for(int i=0;i
char ch=s.charAt(i);
if(ch!=' ')
{
wo = wo+ch;
}
else
{
x=wo.length();
if(x>max)
{
max=x;
w=wo;
}
wo="";
}
}
System.out.println("Longes Word is " + wo);
}
}
4 comments:
The for loop is not complete. Please complete that
class Football
{
static void test(String st)
{
st=st+" ";
int l=st.length();
System.out.println("Entered String is "+st);
System.out.println("Length is : "+l);
int a = 0;
String bin="";
int maxSub=0;
for(int i=0;imax)
{
max=m[k];
maxSub=k;
}
}
System.out.println("The longest word is \'"+st2[maxSub]+"\' with maximum letters "+max);
}
}
This program is absolutely complete and works fine
Post a Comment