Question: please explain this i dont understand how u get the return rows + triangle(rows-1); We have triangle made of blocks. The topmost row has 1

 please explain this i dont understand how u get the return

please explain this i dont understand how u get the return rows + triangle(rows-1);

We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows. triangle(0) +0 triangle(1) 1 triangle(2) 3 Run Expected triangle(0) 0 0 OK Go ...Save, Compile, Run (ctrl-enter) triangle(1) 1 OK ) triangle(2) 3 OK public int triangle(int rows) { if (rows == 0){ return 0; } else{ return rows + triangle(rows-1);|| } } triangle(3) 6 6 OK triangle(4) 10 10 OK 15 15 OK triangle(5) triangle(6) triangle(7) 21 21 OK 2828 OK other tests OK All Correct Good job -- problem solved. You can see our solution as an alternative. See Our Solution next chance Java > Recursion-1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!