arrays - Java program - Counts all the words from a text file, and counts frequency of each word -


i'm beginner programmer , i'm trying 1 program opens text file large text inside , counts how many words contains. should write how many different words in text, , write frecuency of each word in text. had intention use 1 array-string store unique words , 1 int-string store frequency.

the program counts words, i'm little bit unsure how write code correctly list of words , frequency them repeated in text.

i wrote this:

import easyio.*; import java.util.*;  class oblig3a{     public static void main(string[] args){         int cont = 0;         in read = new in (alice.txt);         in read2 = new in (alice.txt);          while(read.endoffile() == false)         {             string info = read.inword();             system.out.println(info);             cont = cont + 1;         }          system.out.println(uniquewords);          final int an_words = cont;          string[] words = new string[an_words];         int[] frequency = new int[an_words];          int = 0;         while(les2.endoffile() == false){            word[i] = read2.inword();            = + 1;         }     } } 

ok, here need do:
1. use bufferedreader read lines of text file, 1 one.
2. create hashmap<string,integer> store word, frequency relations.
3. when read each line of text, use split() words in line of text in array of string[]
4. iterate on each word. each word, retrieve value hashtable. if null value, have found word first time. hence, create new integer value 1 , place in hashmap
if non-null value, increment value , place in hashmap.
5. till not reach eof.

done !


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -