I'm trying to create a Java method that filters figures as follows: The method asks for two int (int n, int x). If n is, for example, 4232 and x is 2, n will be filtered making all 2 of n change to zeros, that is; filterCifrasX (4232, 2) returns the integer 4030. I've tried a few things but I can not. Thanks in advance for the help.
public static int filtraCifrasX(int n, int x) {
if (n < 10) {if (n==x) {return 0;} else {return n;}}
else {
if (n%10 == x) {n = n-n%10;filtraCifrasX(n/10,x);return n;}
else {return filtraCifrasX(n/10,x);}
}
}
This is the method as I have it right now, the problem I have is that if I enter 4232 as I had set an example, it returns 4230; but not 4030, which is what should happen.