public static void evenDigits(int n) {
if (n!=0){
if(n%2 == 0){
evenDigits(n/10);
System.out.print(n%10);
} else{
evenDigits(n/10);
}
}
}
For example:
evenDigits(8342116);
would return 8426
Ok, so the method recursively removes all odd digits from an integer. Currently it prints the correct output. However, instead of printing the output, I want the method to return the integer.
What is the best way to go about this. I tried using string builder to append the n%10 to a string and then parse the SB to an INT but this also placed line breaks where the odd numbers were removed.

New Topic/Question
Reply



MultiQuote







|