java - how to change an index in a StringBuilder based on what the user enters -
i want change index on stringbuilder
based on string user enters example made array have change string used stringbuilder
so. created string have user input , replace index user entered. here have:
arrays inventory = new arrays(); string[] words = inventory.getwords(); string[] category = inventory.getcategory(); string board = ""; stringbuilder builder = new stringbuilder(); for(string s : words) { builder.append(s+"\n"); }
this part of code. part want change index error saying method setcharat
undefined string type. tried other methods replace()
same error. have use strings this:
string word1 = builder.substring(0, 7); board.equals(word1); scanner in = new scanner(system.in); system.out.println("enter letter guess word"); string input = in.nextline(); char achar = builder.charat(0); if (input.equals(achar)){ board.setcharat(0, input); system.out.println(board); }
setup stringbuilder *
's each letter:
string theword = "enter"; stringbuilder board = new stringbuilder(); (int = 0; < theword.length(); i++) { board.append("*"); }
gather users input (not included brevity)
char usersinput = 'e'; // example
find characters match ones in original word , replace * in stringbuilder.
(int = 0; < theword.length(); i++) { if (theword.charat(i) == usersinput) { board.setcharat(i, usersinput); } } system.out.println(board.tostring());
this produce "e**e*"
Comments
Post a Comment