help with this project for java dictionarytxt a and as bear
help with this project for java,
dictionary.txt
a
and
as
bear
beef
brunt
century
consumers
corn
cost
drive
driving
drought
expected
feed
government
heat
in
is
milk
nearly
next
of
pork
price
said
some
states
sweltering
that
the
to
united
up
wednesday
worst
year
Solution
import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner;
public class TypoExample {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner scanner = null;
try {
scanner = new Scanner(new File(\"dictionary.txt\"));
List<String> dictonary = new ArrayList<String>();
while (scanner.hasNext()) {
dictonary.add(scanner.next());
}
scanner.close();
scanner = new Scanner(new File(\"test.txt\"));
Iterator<String> it = null;
while (scanner.hasNext()) {
String word = scanner.next();
it = dictonary.iterator();
boolean flag = false;
while (it.hasNext()) {
String string1 = it.next();
if (string1.contains(word)
|| string1.equalsIgnoreCase(word)
|| (word.substring(0, word.length() - 1)
.equalsIgnoreCase(string1) && word
.contains(\",\"))) {
// System.out.println(word);
flag = true;
break;
}
}
if (flag == false)
System.out.print(\" *\" + word + \"*\");
else
System.out.print(\" \" + word);
}
} catch (Exception e) {
// TODO: handle exception
} finally {
if (scanner != null)
scanner.close();
}
}
}
dictionary.txt:
a
and
as
bear
beef
brunt
century
consumers
corn
cost
drive
driving
drought
expected
feed
government
heat
in
is
milk
nearly
next
of
pork
price
said
some
states
sweltering
that
the
to
united
up
wednesday
worst
year
test.txt:
The worsst drought in the United States in neearly a century is expected to drive up the price of milk, beef
and pork next yeer, the government said Wednesdaay, as consumers bear some of the bruntt of the sweltering
heat that is driving up the cost of feed corrn.
OUTPUT:
The *worsst* drought in the United States in *neearly* a century is expected to drive up the price of milk, beef and pork next *yeer,* the government said
*Wednesdaay,* as consumers bear some of the *bruntt* of the sweltering heat that is *drivng* up the cost of feed *corrn.*


