Create a triangle out of stars using only recursion

前端 未结 10 852
独厮守ぢ
独厮守ぢ 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:41

    i think this should do it

    public void printTriangle (int count) {
       if(count >= 0) {
          printTriangle(count-1);
              for(int i = 0; i < count; i++) {
                  System.out.print("*" + " ");
              }
          System.out.println(); 
       }
    }
    

提交回复
热议问题