• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help reading code  RSS feed

 
Davey Lopez
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My job is to determine what the output is I know it is 18 but I'm having trouble understanding why I'm mostly having trouble with this part can someone help me understand why?


else if(a[size -1] == 0)
return 2 * mystery(a, size -1);
else return 2 * mystery(a,size -1) + 1;



 
Johan Fourie
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basically says if a[5 - 1] is equal to 0
If you look at a[5-1] (or a[4]) does equal 0.
I hope I helped you correctly, as this is only my understanding of the code I read.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The 'mystery' method is a recursive method: it calls itself. (<= Click the link). That concept can be a bit hard to understand if you've never seen it before.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!