// HW08_2b.java // Tim Hilby // Created on April 12, 2006 import java.util.Scanner; public class HW08_2b { // reverse the given line recursively public static String revline(String line) { if (line.length() == 0) { // trivial base case return ""; } else { // take the first character // and add to the end of the // rest of the reversed string return (revline(line.substring(1)) + line.charAt(0)); } } public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.print("This program reverses "); System.out.println("an entire line of input."); String line = ""; System.out.println("Type in your line below:"); System.out.println("(enter in a blank line to quit)"); line = scan.nextLine(); while (line.length() > 0) { System.out.println("Reversed version:"); System.out.println(revline(line)); System.out.println("Next line (leave blank to quit):"); line = scan.nextLine(); } } }