Hi guys!
i need some help with my program and i cant determine what to do next...i'm making a program that will output the longest word in a sentence..
here is my code...
import java.util.Scanner;
class LongestWord4
{
static Scanner console = new Scanner(System.in);
public static void main(String args[])
{
String word, longestWord = "";
System.out.print("Enter sentence: ");
Scanner console = new Scanner(System.in);
String sentense = console.nextLine();
Scanner console2 = new Scanner(sentense);
while ( console2.hasNext() )
{
word=console2.next();
if (word.length() > longestWord.length())
longestWord = word;
}
System.out.print("The longest word was: " + longestWord);
}
}
now my problem is whenever I try to input a sentence with a word with similar length, only the first longest word appears. Well supposedly all distinct words with similar number of characters should appear on the output.
second problem..the output must also disregard the special cases like .,/?:!, etc that is link to the longest word... e.g. get out of here!
the exclamation mark must be disregarded when outputting the word here...
so someone please help me how to figure out..cause i cant think of how to handle this problems..
THANKS!