I need some help here with my java school work. Yesterday I posted one question which is quite similar to this one regarding arrays at Java SE array help needed please and managed to get it solved from the help of you guys.
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 but please advise me if i'm wrong. 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.
Thank you once again and hope you guys can try to understand that I'm a total newbie in programming so try to keep everything simple. :D
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));
}
}
}