/** * Print the digits of a number, recursively!!! * And do it for integers and doubles, both using recursion * and using overloaded methods!!!!! * @author ggtowell * Created Oct 27. 2023 */ public class PrintDigitsRec { public static void main(String[] args) { printRec(1234); //printRec(1.7); } /* * Recursive print digits of an integer */ public static void printRec(int num) { if (num == 0) { return; } System.out.println(num % 10); printRec(num / 10); } /* * Recursively try to make a double into an integer by shifting * the decimal point. Then print its digits! */ public static void printRec(double num) { if (num == Math.floor(num)) { System.out.println("Print digits of " + num); printRec((int) num); return; } System.out.println("Shifting " + num); printRec(num * 10); } }