Ok so this program is soppose to take a String and compare it to a file, the only problem is is that it outputs too high a cout value and im not entirely sure why. If i search for "the" in this file:
"In 2013, major cruise lines are expected to welcome 17.6 million passengers — or more than double the number from just around a decade ago, according to the Cruise Lines International Association. On top of that, the lines also introduced new ships — 13 in 2012 alone and 167 since 2000. All that spells serious competition, with ships trying to offer adventures and amenities that set them apart from the rest. The bottom line? “By creating these flashy experiences, they can draw passengers,” says Sherri Eisenberg, editor of Bon Voyage digital magazine, a publication for cruise fans. But what kind of experiences? Read on for 10 of the latest cruise innovations."
it tells me there are 43 times it is shown , when there really only is 9.
Any help would be greatly appricated.
import java.util.*; import java.util.regex.Pattern; public class Textrepo { public static void main(String[] args) throws Exception { Scanner in= new Scanner(System.in); java.io.File file = new java.io.File("new file"); String s; System.out.print("What string are you looking for?"); s=in.nextLine(); int wordc=0; Scanner parser = new Scanner(file); String textFile = parser.toString(); String[] words = s.split(""); String[] words2 = textFile.split(""); for(int i = 0; i < words.length; i++) { for(int j = 0; j < words2.length; j++) { if(words[i].equals(words2[j])) { wordc++; } else { System.out.print("i"); } } } System.out.print("There are "+ wordc + " repeats of youre string"); parser.close(); } }