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

10th Nov 2020, 8:49 AM
Eric Kazhus
Eric Kazhus - avatar
4 ответов
+ 4
Hope this helps! https://code.sololearn.com/cER3aq5eE5e6/?ref=app Edit: Avinesh is right!! You don't need String input for Character!
10th Nov 2020, 9:12 AM
Minho
Minho - avatar
+ 1
Eric Kazhus https://code.sololearn.com/cuMeD2Onag75/?ref=app I editted your code.Now it works 😁 Check it now.
10th Nov 2020, 9:16 AM
Coder##***
Coder##*** - avatar
+ 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");
10th Nov 2020, 9:18 AM
Avinesh
Avinesh - avatar
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!
10th Nov 2020, 10:11 AM
Eric Kazhus
Eric Kazhus - avatar