finished code for example in section4 chapter8, TryForattedOutput.java