7 Replies - 285 Views - Last Post: 05 October 2013 - 10:07 AM Rate Topic: -----

#1 flipsidemigs01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-September 13

counting occurence of words.. how?

Posted 04 October 2013 - 08:37 AM

So far i got this.

System.out.println("Give the name of the file: ")
String filName = sc.nextLine();

File k = new File(filName);
Scanner sc2 = new Scanner(k);

(have set the file to array "a")
for(int i = 0;i<a.length;i++){
int count = 0;
for(int j = 0;j<a.length;j++){
if(a[i].equals(a[j])){
count++;

System.out.println(a[i] + count)


*i dont get my wanted answer

it should be like

a = 4
the = 142
by = 30

Mod edit - Please :code:

Is This A Good Question/Topic? 0
  • +

Replies To: counting occurence of words.. how?

#2 Ryano121  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1362
  • View blog
  • Posts: 3,002
  • Joined: 30-January 11

Re: counting occurence of words.. how?

Posted 04 October 2013 - 08:45 AM

Have you been introduced to Maps yet (like a HashMap for example)?
Was This Post Helpful? 0
  • +
  • -

#3 flipsidemigs01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-September 13

Re: counting occurence of words.. how?

Posted 04 October 2013 - 09:03 AM

No, we are not allowed to use hashmap,treemap or hashset.
Was This Post Helpful? 0
  • +
  • -

#4 farrell2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 823
  • View blog
  • Posts: 2,534
  • Joined: 29-July 11

Re: counting occurence of words.. how?

Posted 04 October 2013 - 09:15 AM

So, what are you allowed to use? You could always use parallel arrays.

This post has been edited by farrell2k: 04 October 2013 - 09:22 AM

Was This Post Helpful? 0
  • +
  • -

#5 flipsidemigs01  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 26-September 13

Re: counting occurence of words.. how?

Posted 04 October 2013 - 11:47 AM

Thats the one im using. but i cant get it right.
Was This Post Helpful? 0
  • +
  • -

#6 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 7644
  • View blog
  • Posts: 12,890
  • Joined: 19-March 11

Re: counting occurence of words.. how?

Posted 04 October 2013 - 12:11 PM

Okay, explain your algorithm in English. You read the file, and then what?
Was This Post Helpful? 0
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: counting occurence of words.. how?

Posted 04 October 2013 - 09:30 PM

View Postflipsidemigs01, on 04 October 2013 - 12:03 PM, said:

No, we are not allowed to use hashmap,treemap or hashset.

Who said that ? Want to see the quoted assignment :)
so write your own..... not that difficult if you cut & paste the code from the API
You will be surprise how concise it is
Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2687
  • View blog
  • Posts: 11,349
  • Joined: 20-September 08

Re: counting occurence of words.. how?

Posted 05 October 2013 - 10:07 AM

http://technojeeves....d-count-in-java

Difficult to know what containers to suggest since you only say what you can't use
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1