aspose file tools*
The moose likes Java in General and the fly likes Java direct Recursion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Java direct Recursion" Watch "Java direct Recursion" New topic
Author

Java direct Recursion

mark jacob
Greenhorn

Joined: Oct 07, 2009
Posts: 1
I want to convert this mutual recursion prog into direct recursion. Any Help how to do this

class Arec {

int a;
int b;
static long h(int k)
{ a++;
if (k == 0) return 0;
else return h(k - 1) + i(k - 1);
}

static long i(int k)
{ b++;
if (k == 0) return 1;
else return h(k) * i(k - 1);
}


public static void main(String argv[])
{ int k;
for (k = 0; k< 4; k++)
{ a = 0;
b = 0;
System.out.println("\n h("+k+") = "+h(k)+", i("+k+") = "+i(k));

}
}

}
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 802

Hi Mark,

Welcome to JavaRanch

UseCodeTags
By using code tag your code will be easier to read.


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39828
    
  28
Who inflicted that exercise on you?
Please tell us what you think you should do. In fact I think it is better with the two methods.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Java direct Recursion