Question: How do i know the output that triangle(5) is 15 and triangle(4) is 10 and etc. what does return rows + triangle(rows - 1); means?

How do i know the output that triangle(5) is 15 and triangle(4) is 10 and etc. what does return rows + triangle(rows - 1); means? what does the code do?Please explain everything clearly.
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 Go ...Save, Compile, Run (ctrl-enter) public int triangle(int rows) { if(rows == 0){ return 0; } else{ return rows + triangle(rows - 1); } Expected Run triangle(0) 0 0 OK triangle(1) 1 1 OK triangle(2) 3 3 OK triangle(3) 6 6 OK triangle(4) 1010 OK triangle(5) 15 15 OK triangle(6) 21 21 OK triangle(7) 2828 OK other tests OK All Correct
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
