Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Stars {
- /**
- * Program: Stars.java
- * Purpose: Demonstrate recursion
- * Creator: Chris Clarke
- * Created: 23.10.2012
- */
- public static void main(String[] args) {
- for (int i=5; i>0; i--) {
- printStars(i);
- System.out.println(); // new line
- }
- }
- public static void printStars(int n) {
- System.out.print("*");
- if (n>1) printStars(n-1); // recursive method call
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement