java - Recursion - returning a new number with bigger digits than the parameter -


i have exercise in have write recursive method receives integer , digit d. method has return new number, consisting digits bigger d.

for example, number 19473, , digit 3, returned number 947.

so far haven't gotten progress in code, don't have show you. method's signature:

public static int filter(int n, int d) 

any great,

thank you.

here answer in great details:

int filter(int n, int d) {     if (n >= 0 && d >= 0) {    // n , d non-negetive          if (n == 0) {   // terminating criteria             return 0;         } else {             int currdigit = n % 10;             if (n % 10 > d) {                 return filter(n / 10, d) * 10 + currdigit; //gathering digits greater thand d             } else {                 return filter(n / 10, d);  // ignoring digits less or equal d             }         }      }     return -1; } 

one thing should know, if new in coding , want great coder! advice is, don't take away opportunities brain think coding problems! trust brain. keep patient. try , try again.

cheers , happy coding!


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -