Create a triangle out of stars using only recursion

前端 未结 10 858
独厮守ぢ
独厮守ぢ 2020-12-06 06:52

I need to to write a method that is called like printTriangle(5);. We need to create an iterative method and a recursive method (without ANY iteration). The out

10条回答
  •  情歌与酒
    2020-12-06 07:21

    You can do it like this:

    The method gets the number of stars as a parameter. Let's call it n.

    Then it:

    1. calls itself recursively with n-1.

    2. prints a line with n stars.

    Make sure to do nothing if n == 0.

提交回复
热议问题