Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DATABASE Administrator Make A Difference

Authors: Mohciine Elmourabit

1st Edition

B0CGM7XG75, 978-1722657802

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago