Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.24 KB | None | 0 0
  1. int total = 0;
  2.  
  3. public int triangle(int rows) {
  4.   if (rows == 0) {
  5.     return total;
  6.   }
  7.  
  8.   if (rows == 1) {
  9.     return total + 1;
  10.   }
  11.  
  12.   else {
  13.     total += rows;
  14.     rows--;
  15.     triangle(rows);
  16.   }
  17.  
  18.   return total;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement