Answered You can hire a professional tutor to get the answer.

QUESTION

I could use some help turning the following recursive code into an iterative code. public class RecursiveNum { public static int recursiveNum (int

I could use some help turning the following recursive code into an iterative code.

public class RecursiveNum {

  public static int recursiveNum (int n){

       if (n <= 0)

           return 2;

       else

       return (2 * recursiveNum(n-1))+1; //recursive call here

   }

   public static void main (String args[]) {

       for(int i = 0; i < 10; i++) {

           }

       Scanner stdin = new Scanner (System.in);

       System.out.print("Please enter a number: ");

       int n = stdin.nextInt();

       System.out.println("The " + n + "-th trinagular number is: " +

               recursiveNum(n));

   }

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question