/** * This class contains a number of examples of recursive methods. * * @author Franck van Breugel */ public class Print { /** * Prints the given number of *'s. * * @param n an integer. * @pre. n >= 0. */ public static void stars(int n) { if (n == 0) { // do nothing } else { System.out.print('*'); Print.stars(n - 1); } } /** * Prints the given number of *'s followed by the given number * of +'s. * * @param n an integer. * @pre. n >= 0. */ public static void starsAndPlusses(int n) { if (n == 0) { // do nothing } else { System.out.print('*'); Print.starsAndPlusses(n - 1); System.out.print('+'); } } /** * Prints done. * * @param n an integer. * @pre. n >= 1. */ public static void done(int n) { if (n == 1) { System.out.println("done"); } else { if (n % 2 == 0) { Print.done(n / 2); } else { Print.done(3 * n + 1); } } } }