1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
| String mot ;
String aux;
int i=0;
String ligneIN=null;
int nbmots;
int nbMotsDiff=0;
StringTokenizer st;
String tabMotsDiff[]=new String [11000];
int tabFreq[]=new int [11000];
boolean trouve;
BufferedReader fin=new BufferedReader(new FileReader("test.txt"));
while((ligneIN=fin.readLine())!=null)
{
st=new StringTokenizer(ligneIN," ?,.;:!");
while(st.hasMoreTokens()&&calcul<11)
{
mot=st.nextToken();
calcul++;
for( i=0,trouve=false;i<nbMotsDiff&&!trouve;i++)
{
if(tabMotsDiff[i].equals(mot))
trouve=true;
}
if(trouve)
tabFreq[i-1]++;
else
{
tabMotsDiff[nbMotsDiff]=mot;
tabFreq[nbMotsDiff]=1;
nbMotsDiff++;
}
nbmots++;
}
}
fin.close(); |
Partager