Hyroko
  • Hyroko
I'm having trouble and, although I'm pretty good with java, for some reason I'm getting a weird looping bug that I can't seem to squash
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Hyroko
  • Hyroko
Here is the method that has the issue ``` private ArrayList getLocations(String[] names) { String str; String[] fixedNames = removeCopies(names); int count = 0; int lineNumber = 1; boolean done = false; ArrayList instances = new ArrayList(); for (String name : names) { try { instances.add(name); Scanner scan = new Scanner(new File( "C://Users//Owner//Desktop/test.txt")); while (scan.hasNextLine()) { String line = scan.nextLine(); Pattern p = Pattern.compile(name); Matcher m = p.matcher(line); while (m.find()) { count++; } if (count >= 1) { for (int j = 0; j < count; count--) { instances.add(lineNumber); } count = 0; } else { count = 0; instances.add(name); } lineNumber++; } } catch (FileNotFoundException ex) { Logger.getLogger(HashTable.class.getName()).log(Level.SEVERE, null, ex); } } for (Object instance : instances) { System.out.println(instance); } return instances; } ```
Hyroko
  • Hyroko
When I run this, I get this result (times like....... 1000) ``` java.util. 1 java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. 1 java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. java.util. 15 15 15 15 15 15 15 15 15 15 15 15 15 1
Hyroko
  • Hyroko
That's not the whole arraylist. Just a small chunk of it. It's only supposed to have one instance of each name in it.

Looking for something else?

Not the answer you are looking for? Search for more explanations.