word frequency problem

Posted by davit-datuashvili on Stack Overflow See other posts from Stack Overflow or by davit-datuashvili
Published on 2010-05-03T07:36:11Z Indexed on 2010/05/03 7:58 UTC
Read the original article Hit count: 438

Filed under:
|

hi in programming pearls i have meet following problem question is this:print words in decreasing frequency or as i understand probllem is this suppose there is given string array let call it s words i have taken randomly it does not matter
String s[]={"cat","cat","dog","fox","cat","fox","dog","cat","fox}; and we see that string cat occurs 4 times fox 3 times and dog 2 times so result will be such cat fox dog i have following code in java mport java.util.*; public class string {

public static void main(String[] args){

String s[]={"fox","cat","cat","fox","dog","cat","fox","dog","cat"}; Arrays.sort(s); int counts; int count[]=new int[s.length]; for (int i=0;i

} } or i have sorted array and create count array where i write number of each word in array problem is that somehow index of integer array element and string array element is not same how to do such that print words according tu maximum elements of integer array? please help me

© Stack Overflow or respective owner

Related posts about algorithm

Related posts about java