import java.io.*; /** *
Given a file of text, footnotes are delimited by special bracketing * symbols [ and ] . Footnotes, when encountered, are NOT to be printed * as normal text, but are instead stored in a footnote queue. Then, when * EOF is encountered after all the normal text, numbered footnotes are * dequeued and printed.
* *Command-line:
** java FootNotes < filename ** * @author G.D.Thurman * @version 99.09.26 */ public class FootNotes { private static final char BEGIN_FOOTNOTE_CHAR = '[', END_FOOTNOTE_CHAR = ']'; public static void main(String[] argv) throws IOException { Queue footnotesQ = new Queue(); StringBuffer footnote = new StringBuffer(); int c; boolean inFootnote = false; while ((c = System.in.read()) != -1) { char ch = (char) c; if (!inFootnote) { if (ch == BEGIN_FOOTNOTE_CHAR) inFootnote = true; else System.out.print(ch); } else if (ch == END_FOOTNOTE_CHAR) { footnotesQ.enqueue(footnote); inFootnote = false; footnote = new StringBuffer(); } else footnote.append(ch); } for (int n = 1; !footnotesQ.isEmpty(); n++) System.out.println(n + ": " + footnotesQ.dequeue()); } }