I'm trying to write a function that receives a String, and replaces the string characters from right to left, by zero. Also, I'd like to make it accumulate and save those changes. For example:
String test = "12345678"
When I iterate through it, I'd like the result to be:
- "12345670"
- "12345600"
- "12345000"
- "12340000"... and so on.
Here's the code I've written so far:
public String test = "12345678";
public String replaceFromRightToLeft(String test) {
for (int i = test.length() -1; i >= 0; i--) {
test.replace(test.charAt(i), '0');
}
return test;
}
When I run it, I get results like:
- 12345670
- 12345608
- 12345078
- 12340678
- 12305678
- 12045678
- 10345678
- 02345678
So, what should I do to "save" the previous changes?