/* * Kyle Pierce * CSE 143 * * Client program with the recursive code we wrote in class */ public class Recursion { public static void main(String[] args) { writeStars(5); writeStars2(5); Scanner input = new Scanner(new File("words.txt")); reverse(input); } // pre: n >= 0 // post: produces an output line of exactly n stars public static void writeStars(int n) { for (int i = 0; i < n; i++) { System.out.print("*"); } System.out.println(); } // pre: n >= 0 // post: produces an output line of exactly n stars public static void writeStars2(int n) { if (n <= 0) { System.out.println(); } else { System.out.print("*"); writeStars2(n - 1); } } // print the lines of the file in the Scanner in reverse order public static void reverse(Scanner input) { if (input.hasNextLine()) { String line = input.nextLine(); reverse(input); System.out.println(line); } } }