Please check this code snippet.
I made it recursive but it doesn't work. It enters the method again but it doesn't execute the statement in between.
int check_month(int a)
{
if(a>12)
{
a-=12;y1++;
if(a>12)
{
System.out.println("check");
check_month(a);
}
}
System.out.println("exit");
return a;
}
Please check and let me know the error.
Is This A Good Question/Topic? 0
[Edit]
Response from OP - moved here from an answer, since deleted. - Henry
check the code with following calculation
initially a=50
enters method, a>12=true
enters if block. a=a-12;ie 50-12=38. a=38
again enters if 2 . a>12 ie 38>12. recursive procedure called. goes to start.
again a=38
a>12, a=a-12, ie 38-12=26, a=26;
again enters if 2 . a>12 ie 26>12. recursive procedure called. goes to start.
again a=26
a>12, a=a-12, ie 26-12=14 a=14;
again enters if 2 . a>12 ie 14>12. recursive procedure called. goes to start.
again a=14
a>12, a=a-12, ie 14-12=2, a=2;
return 2;
it should work like this , but it doesn't.....!!!
[/Edit]