// Scott DeRuiter 7/17/01 // PrintChars.java // Use recursion to deconstruct a String, and print one char per line. // 7/20/2011 - Greenstein: Changed TextReader to Scanner public class PrintChars { private String chunk; public PrintChars ( ) { chunk = ""; } public static void main ( String [] args ) { PrintChars p = new PrintChars ( ); p.GetPhrase ( ); p.Deconstruct ( ); } public void GetPhrase ( ) { Scanner console = new Scanner ( System.in ); do { System.out.print ( "\n\nEnter a phrase: " ); chunk = console.nextLine ( ); } while ( chunk == null ); System.out.println ( "\n\n" ); } public void Deconstruct ( ) { OneChar ( chunk ); System.out.println ( "\n\n" ); } public int OneChar ( String c ) { if ( c.equals ( "" ) ) return 1; else { char first = c.charAt ( 0 ); c = c.substring ( 1 ); System.out.println ( first ); return OneChar ( c ); } } }