I am doing some programming for my Java school work. Yesterday I posted a question which is quite similar to this one regarding arrays and I managed to get it solved.
This time round, I am required to prompt the user to enter a series of words regarding of the number and from there the application will determine the longest word of all and print to console stating the longest word as well as the length of it.
Although, we weren't given any hint on how to go about it but I thought that by using vector could be the only solution. As for now, I only manage to print to console no matter how many words the user input but I have no idea how to be able to add each individual to the vector and compare them regarding their length.
I am a total beginner in programming.
import java.util.*;
class LongestWord2 {
public static void main(String [] args) {
System.out.println("Please enter your words");
Scanner userInput = new Scanner(System.in);
Vector <String> v = new Vector <String>();
while (userInput.hasNext()) {
v.add(userInput.next());
System.out.println(userInput.next());
System.out.println(v.get(0));
}
}
}