Advertisement
brilliant_moves

Stars.java

Oct 23rd, 2012
210
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.40 KB | None | 0 0
  1. public class Stars {
  2.  
  3.     /**
  4.     *   Program:    Stars.java
  5.     *   Purpose:    Demonstrate recursion
  6.     *   Creator:    Chris Clarke
  7.     *   Created:    23.10.2012
  8.     */
  9.  
  10.     public static void main(String[] args) {
  11.         for (int i=5; i>0; i--) {
  12.             printStars(i);
  13.             System.out.println(); // new line
  14.         }
  15.     }
  16.  
  17.     public static void printStars(int n) {
  18.         System.out.print("*");
  19.         if (n>1) printStars(n-1);   // recursive method call
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement