Best writers. Best papers. Let professionals take care of your academic papers

Order a similar paper and get 15% discount on your first order with us
Use the following coupon "FIRST15"
ORDER NOW

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

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));

}

}

 
Looking for a Similar Assignment? Order now and Get 10% Discount! Use Coupon Code "Newclient"