Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. // Bunny Ears
  2. private int ears = 0;
  3.  
  4. public int bunnyEars(int bunnies) {
  5.   if (bunnies > 0) {
  6.     ears += 2;
  7.     bunnies--;
  8.     bunnyEars(bunnies);
  9.   }
  10.  
  11.   return ears;
  12. }
  13.  
  14. //////////////////////////////////////
  15.  
  16. // Triangle
  17. int total = 0;
  18.  
  19. public int triangle(int rows) {
  20.   if (rows == 0) {
  21.     return total;
  22.   }
  23.  
  24.   else {
  25.     total += rows;
  26.     rows--;
  27.     triangle(rows);
  28.   }
  29.  
  30.   return total;
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement