• 11-09-2012, 03:16 AM
zygmfb
I need to make run() a recursive method, and i have no way of doing it. I tried many ways but cannot do it. Can someone please help me, it's due tomorrow and I've spent hours on it.

Program:
Write a program that prompts for a positive integer and displays all permutations of the odd digits of that length. Display these values in ascending order. For example, if the length is 3, your program should display:

111
113
115
117
119
131
133
135
. . .

^there shouldn't be an even digit in any number.

Code:

```  import java.util.Scanner;   public class OddDigits   {       public static void main(String [] arg)       {         Scanner x = new Scanner(System.in);               System.out.print("Enter a number: ");         int a = x.nextInt();         int b = 1;                 run(a, b);       }         public static boolean isOdd(int a)       {         int n =0;         while (a > 1)         {             if(a%2 == 0)               return false;             a = a/10;         }                   return true;       }             public static void run(int a, int b)       {         int upLim = (int)Math.pow(10,a);         int lowLim = (int)Math.pow(10, a-1) -1;                 int start = (int)Math.pow(10, a-1);                 while(start < upLim)         {             if(isOdd(start) == true)               System.out.println(start);             start++;         }         //run(a, start++);       }     }```