what did I do wrong to get an error in the replace() method?

27 Views Asked by At

My teacher asked us to design a program that receives a string value and then converts all numeric characters to *.

code sample I tried the replaces method but it did not work.

1

There are 1 best solutions below

0
Leno On

You have to use regular expressions. In addition to that, since you want to replace all numbers, you should use replaceAll instead of replace. This should do the job:

s.replaceAll("[0-9]", "*")

Use it to instead of

s.replaces(...)