Write a program to accept a string from the user and find the smallest word.
ananya071:
in Java
Answers
Answered by
2
heya,
public class smallest_word
{
public static void main(String s)
{
s = s.trim(); s = s + " " ;
String w="",minw=''";
int I=s.length();
int min=l;
for(int x=0;x<I;x++)
{
char ch=s.charAt(x);
if(ch!=32)
{
w = w + ch;
}
else
{
int wl=w.length();
if(wl<min)
{
min =wl;
minw=w;
}
w = "";
}
}
System.out.println(minw);
}
}
#hope it helps...
public class smallest_word
{
public static void main(String s)
{
s = s.trim(); s = s + " " ;
String w="",minw=''";
int I=s.length();
int min=l;
for(int x=0;x<I;x++)
{
char ch=s.charAt(x);
if(ch!=32)
{
w = w + ch;
}
else
{
int wl=w.length();
if(wl<min)
{
min =wl;
minw=w;
}
w = "";
}
}
System.out.println(minw);
}
}
#hope it helps...
Similar questions