Longest Words

Given a sentence the task is to print all longest words present in the sentence.

Example: Consider the sample text “Lorem Ipsum is simply dummy text of the printing and type setting industry”. The program should find the longest words in this sentence i.e., “printing, industry”.

Note: This program will print all longest words having same number of characters.

Java
import java.util.*;
public class LongestWords
{
    public static void main(String[] args) 
    {
        int l=0,wl=0,max=0;
        String str="",word="",mWord="";
        char ch=' ';
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a sentence:");
        str=sc.nextLine();
        str=str+" ";
        l=str.length();
        for(int i=0;i<l;i++)
        {
            ch=str.charAt(i);
            if(ch==' ')
            {
                wl=word.length();
                if(wl>max)
                {
                    max=wl;
                    mWord=word;
                }
                else if(wl==max)
                {
                    mWord=mWord+", "+word;
                }
                word="";
            }
            else
            {
                word=word+ch;
            }
        }
        System.out.println("Longest Words: "+mWord);
    }
}
Java