Java Reference
In-Depth Information
If the file contained this text, your program should output the following text:
import java.util.*;
public class Program {
public static void main(String[] args) {
System.out.println("Hello, world!");
}
public static void foo() {
System.out.println("Goodbye!");
}
}
12. Write a method called printDuplicates that takes as a parameter a Scanner containing a series of lines. Your
method should examine each line looking for consecutive occurrences of the same token on the same line and print
each duplicated token, along with the number of times that it appears consecutively. Nonrepeated tokens are not
printed. You may ignore the case of repetition across multiple lines (such as if a line ends with a given token and the
next line starts with the same token). You may assume that each line of the file contains at least 1 token of input. For
example, consider the following input:
hello how how are you you you you
I I I am Jack's Jack's smirking smirking smirking smirking revenge
bow wow wow yippee yippee yo yippee yippee yay yay yay
one fish two fish red fish blue fish
It's the Muppet Show, wakka wakka wakka
Your method should produce the following output:
how*2 you*4
I*3 Jack's*2 smirking*4
wow*2 yippee*2 yippee*2 yay*3
wakka*3
Programming Projects
1. Students are often asked to write term papers containing a certain number of words. Counting words in a long paper
is a tedious task, but the computer can help. Write a program that counts the number of words, lines, and total char-
acters (not including whitespace) in a paper, assuming that consecutive words are separated either by spaces or end-
of-line characters.
2. Write a program that compares two files and prints information about the differences between them. For example,
consider a file data1.txt with the following contents:
This file has a great deal of
text in it which needs to
be processed.
Search WWH ::




Custom Search