Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java direct Recursion

 
mark jacob
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 802
Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mark,

Welcome to JavaRanch

UseCodeTags
By using code tag your code will be easier to read.
 
Campbell Ritchie
Sheriff
Posts: 51405
87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic