java - replace dash by position with user input then store -


i'm working on hangman app right now. programming , trying @ moment replace dash in tw position (pos) user input (input) store array... can't find issue , driving me insane!!! please me?

public static void main(string[] args) {     //get random array element     system.out.println("welcome hangman app");     string array[] = new string[10];     array[0] = "hamlet";     array[1] = "mysts of avalon";     array[2] = "the iliad";     array[3] = "tales edger allan poe";     array[4] = "the children of hurin";     array[5] = "the red badge of courage";     array[6] = "of mice , men";     array[7] =  "utopia";      array[8] =  "chariots of gods";     array[9] =  "a brief history of time";      arraylist<string> list = new arraylist<string>(arrays.aslist(array));     collections.shuffle(list);     string s = list.get(0);     //for testing     system.out.println(s);       //replace non-white space char dashes     string tw = s.replaceall("\\s", "-");         //get user input     system.out.println("enter letter: ");     string input = sc.next();      //find position of user input , replace     int pos = s.indexof(input);     char ch = input.charat(pos);     char[] answer = tw.tochararray();     //answer[pos] = input;      //test      system.out.println(answer);   } 

char inp = input.charat(0); //find position of user input , replace char[] answer = tw.tochararray(); for(int = 0; < answer.length; i++){     if(s.charat(i) == inp)         answer[i] = inp; } 

now working 1 character. should encapsulate while loop i.e

int numerror = 0; int maxerror = a_number;  boolean finished = false;  while(!finished && numerror < maxerror){     do_all_the_things_you_are_doing_now;      if(ch not exist in answer)         numerror++;      else{         if(there no "_" in answer)              finished = true;     } } 

Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -