Java SE vector array help please -


i need here java school work. yesterday posted 1 question quite similar 1 regarding arrays @ java se array needed please , managed solved of guys.

this time round, required prompt user enter series of words regarding of number , there application determine longest word of , print console stating longest word length of it.

although, weren't given hint on how go thought using vector solution please advise me if i'm wrong. now, manage print console no matter how many words user input have no idea how able add each individual vector , compare them regarding length.

thank once again , hope guys can try understand i'm total newbie in programming try keep simple. :d

import java.util.*;  class longestword2 {     public static void main(string [] args) {                        system.out.println("please enter 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));         }        } } 

if want continue getting response scanner , keep checking longest name can use 1 implement in last question changes.

sample:

system.out.println("please enter words");     scanner userinput = new scanner(system.in);      vector<string> v = new vector<string>();     string longest = "";     longest = userinput.nextline(); //get first array of words checking     v.add(longest);      while (true) {          for(string s : v) //iterate array of words         {             if(longest.length() < s.length()) //check if last longest word greater current workd                 longest = s; //if current word longer make longest word         }         system.out.println("longest word: " + longest + " lenght: " + longest.length());          v.add(userinput.nextline());     } 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -