Java Reference
In-Depth Information
10. Write a method called stripHtmlTags that accepts a Scanner representing an input file containing an HTML web
page as its parameter, then reads that file and prints the file's text with all HTML tags removed. A tag is any text
between the characters < and > . For example, consider the following text:
<html>
<head>
<title>My web page</title>
</head>
<body>
<p>There are many pictures of my cat here,
as well as my <b>very cool</b> blog page,
which contains <font color="red">awesome
stuff about my trip to Vegas.</p>
Here's my cat now:<img src="cat.jpg">
</body>
</html>
If the file contained these lines, your program should output the following text:
My web page
There are many pictures of my cat here,
as well as my very cool blog page,
which contains awesome
stuff about my trip to Vegas.
Here's my cat now:
You may assume that the file is a well-formed HTML document and that there are no < or > characters inside tags.
11. Write a method called stripComments that accepts a Scanner representing an input file containing a Java program as
its parameter, reads that file, and then prints the file's text with all comments removed. A comment is any text on a line
from // to the end of the line, and any text between /* and */ characters. For example, consider the following text:
import java.util.*;
/* My program
by Suzy Student */
public class Program {
public static void main(String[] args) {
System.out.println("Hello, world!"); // a println
}
public static /* Hello there */ void foo() {
System.out.println("Goodbye!"); // comment here
} /* */
}
Search WWH ::




Custom Search