Computer Science, asked by GauravKumarRai, 1 year ago

Write a program to accept a string from the user and find the smallest word.


ananya071: in Java
GauravKumarRai: yes

Answers

Answered by ananya071
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...

GauravKumarRai: have you compiled thos program
GauravKumarRai: by the way thanks for giving solution
ananya071: can u mark brainliest
GauravKumarRai: yes,but just now no option is coming to mark it as brainliest
GauravKumarRai: yaa it helps
GauravKumarRai: i marked your answer as brainliest
Similar questions