0
How to replace user inputed letter using arrays
So basically i have to use arrays to print out each letter separately, that part in my code works, and second part is that i have to replace any letter i want with an x for example: i input pizza and want to replace a with x, or z with x, the problem in my code is, it doesnt print out new word with replaced letter. Cant figure it out, what is the problem..anyone can help? https://code.sololearn.com/c2SRB6lsi1Ek/?ref=app
4 Respostas
+ 4
Hope this helps!
https://code.sololearn.com/cER3aq5eE5e6/?ref=app
Edit: Avinesh is right!! You don't need String input for Character!
+ 1
Eric Kazhus
https://code.sololearn.com/cuMeD2Onag75/?ref=app
I editted your code.Now it works 😁
Check it now.
+ 1
When you are taking only a character then it need not be a string input.
char enterCharacter;
enterCharacter= scan.next().charAt(0);
String newWord = String.valueOf(array).replaceAll(Character.toString(enterCharacter), "x");
0
Hope this helps!
https://code.sololearn.com/cER3aq5eE5e6/?ref=app
Edit: Avinesh is right!! You don't need String input for Character!
When you are taking only a character then it need not be a string input.
char enterCharacter;
enterCharacter= scan.next().charAt(0);
String newWord = String.valueOf(array).replaceAll(Character.toString(enterCharacter), "x");
thanks guys that i was looking for!!it works!