import java.io.*; import java.util.*; // Some examples of recursion. public class Recurse { public static void main(String[] args) throws FileNotFoundException { writeStars1(10); writeStars2(7); reverse(new Scanner(new File("story.txt"))); } // Iterative method that produces an output // line of exactly n stars // pre: n >= 0 public static void writeStars1(int n) { for (int i = 0; i < n; i++) { System.out.print("*"); } System.out.println(); } // Recursive method that produces an output // line of exactly n stars // pre: n >= 0 public static void writeStars2(int n) { // recursion zen if (n == 0) { System.out.println(); } else { System.out.print("*"); writeStars2(n - 1); } } // Reads in the lines from the Scanner, printing // them to standard out in reverse order. public static void reverse(Scanner input) { if (input.hasNextLine()) { String line = input.nextLine(); reverse(input); System.out.println(line); } } }