
Write a program to read a string composed of an unknown number of words, then count the number of words in the string, and Display the longest and shortest words, with first letter Uppercase and rest in lowercase.??

Hi Friend,
Try the following code:
import java.util.*;
public class StringExample1
{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.println("Enter String: ");
String st=input.nextLine();
String[] str = st.split(" ");
String longest = str[0];
String shortest = str[0];
for(String s : str)
{
if(s.length() > longest.length()){
longest = s;
}
if(s.length() < shortest.length()){
shortest = s;
}
}
String str1=longest.substring(0,1).toUpperCase();
String str2=longest.substring(1).toLowerCase();
System.out.println("Longest Word is: "+(str1+str2));
String str3=shortest.substring(0,1).toUpperCase();
String str4=shortest.substring(1).toLowerCase();
System.out.println("Shortest Word is: "+(str3+str4));
}
}
Thanks

thanks alot ..
but how did you use for loop without using ( initial expression & logical expression & update expression ) ?? and why you didn't use console ?? I think the code will be smaller if we use console !!
wating you .. And want to tell U that I am using JGrasp program ...
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.