// Hunter Schafer, CSE 143 // Examples for recursion public class RecursionExamples { /* Iterative solution public static void writeStars(int n) { for (int i = 0; i < n; i++) { System.out.print("*"); } System.out.println(); } */ // Prints out a line of n stars public static void writeStars(int n) { if (n == 0) { // base System.out.println(); } else { // recursive System.out.print("*"); writeStars(n - 1); } } // Given a Deck of cards, prints them out in reverse order // The card at the top of the deck will be printe last, // the card on the bottom first. public static void reverseDeck(Deck cards) { if (cards.hasNextCard()) { Card card = cards.nextCard(); reverseDeck(cards); System.out.println(card); } } }