printStripped
Category: Programming
Author: Stuart Reges
Book Chapter: 5.3
Problem: printStripped
Write a method printStripped that takes a String
as an argument and that prints a complete line of output with any comments
stripped from the String. Comments are defined to be characters enclosed in
the characters "<" and ">". More precisely, text is "normal" until you
encounter a "<" character. From that point on the text is considered a
comment until you encounter a ">" character, at which point you return to
normal text. This definition allows for "<" inside a comment and ">"
outside a comment. You may assume that there are no unclosed comments in
the String.
For example, the following sequence of calls:
printStripped("this is plain text");
printStripped("this has a normal comment <right here> to be removed");
printStripped("this has multiple less-than in a comment ");
printStripped("this > has greater-than outside a comment >>");
printStripped("this has multiple comments.");
should produce the following output:
this is plain text
this has a normal comment to be removed
this has multiple less-than in a comment
this > has greater-than outside a comment >>
this has multiple comments.
Write your solution to printStripped below.