//PrintOddDigits.java
//Prints the odd digits of an integer in the original order.

public class PrintOddDigits
{
    public static void main(String[] args)
    {
        printOddDigits(123);
        System.out.println();
        printOddDigits(54321);
        System.out.println();
        printOddDigits(2468);
        System.out.println();
        printOddDigits(97531);
        System.out.println();
        printOddDigits(3);
        System.out.println();
    }

    /**
        Print the odd digits of an integer in the same order as they
        appear in the integer.
        @param n The integer whose odd digits are to be printed.
        <p>Pre:<p>n has been initialized with a positive integer.
        <p>Post:<p>Only the odd digits of n have been displayed,
        in the same order in which they appeared in n.
    */
    public static void printOddDigits(int n)
    {
        if (n < 10)
        {
            if (n % 2 == 1)
                System.out.print(n);
        }
        else
        {
            int temp;
            temp = n % 10;
            printOddDigits(n / 10);
            if (temp % 2 == 1) System.out.print(temp);
        }
    }
}

