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
Post a Comment