Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 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-1Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started