import java.util.*;
class Exam3
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a String: ");
String word1 = "", word2 = "";
int l1 = 0, l2 = 0;
while(sc.hasNext())
{ word1 = sc.next();
l1 = word1.length();
if(l1 > l2)
{
l2 = l1;
word2 = word1;
}
}
System.out.println("Longest Word: " + word2);
System.out.println("Length of Word: " + l2);
}
}
The code isn't working. Prompting the user is successful, but nothing else happens. If you input a String and press Enter, it goes to the next line, where you can input again, etc. etc.