java - Wheel of fortune loop simple -


i trying write program game wheel of fortune, , want take in user input word start game make guesses after that. far have this.

string enterphrase = (" enter phrase : ");         string guess = "";     scanner input = new scanner (system.in);     boolean notdone = true;     while (notdone)     {         notdone = false;         for(char guessletter : enterphrase.tochararray()){              if(guess.indexof(guessletter) == -1){                 system.out.println('*');                 notdone = true;              } else {                      system.out.println(guessletter);                     }             }                 if( ! notdone) {break;}                     system.out.println("guess letter: ");                     string letter1 = input.next();                     guess += letter1;        }     system.out.println("hooray! took   guesses" );   } } 

and prints out this:

guess letter:  d  - - - - - - - - - - - - - - - - - - 

if on how make dashes print horizontally. , have input on each letter guess if right , @ end of program count how many times took them complete word.

system.out.println() prints string console , concatenates endline string.

if want print dashes horizontally, needing use system.out.print() - not concatenate endlines. should used when you're printing individual letters of guess (but not when you're printing "guess letter:").

to calculate how many guesses requires user whole string correct, store variable, int count, initialized 0. every time guess, increment counter 1.


Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -