The Darkness
17-06-2005, 10:50
sto cercando di fare una specie di controllo ortografico:
dato il testo "a" e il testo "b" devo controntare che il testo "b" contenga tutte parole esistenti nel testo "b".
Ho crecato di lavorare con vettori, ma non riescoa capire perchè non funziona!
Vi allego il codice che ho scritto
import java.io.*;
import java.util.*;
public class provolone {
public static void main(String[] args) throws IOException {
String nextStr = null;
BufferedReader filebuf =
new BufferedReader(new FileReader("c:\\ortografia.txt"));
nextStr = filebuf.readLine();
StringTokenizer st = new StringTokenizer(nextStr);
int numero = st.countTokens();
String[] vett_orto = new String[numero];
int i = 0;
while (st.hasMoreTokens()) {
vett_orto[i] = st.nextToken();
      
i++;
}
String nextStr2 = null;
BufferedReader filebuf2 =
new BufferedReader(new FileReader("c:\\scrivimi.txt"));
nextStr2 = filebuf2.readLine();
StringTokenizer st2 = new StringTokenizer(nextStr2);
int numeros = st2.countTokens();
String[] vett_sorg = new String[numeros];
int j = 0;
while (st2.hasMoreTokens()) {
vett_sorg[j] = st2.nextToken();
      
j++;
      	
}
int s = 0;
String[] vett = new String[vett_sorg.length];
/*boolean non_trovata = true;
for (int k = 0; k < vett_sorg.length; ++k) {
for (int t=0; t < vett_orto.length; ++t) {
non_trovata = true;
if (vett_sorg[k].compareToIgnoreCase(vett_orto[t])==0) {
non_trovata = false;
break;
}
}
if (non_trovata = true) {
vett[s] = vett_sorg[k];
++s;
}
}*/
int k=0;
boolean consentita = false;
for( k=0; k<vett_sorg.length; k++) {
for(int t=0; t<vett_orto.length; t++)
if(vett_sorg[k].compareToIgnoreCase(vett_orto[t])==0) {
consentita = true;
break;
}
}
if(consentita = false) {
System.out.println("La parola " + vett_sorg[k] + " non è consentita!");
}
consentita = false;
}
}
dato il testo "a" e il testo "b" devo controntare che il testo "b" contenga tutte parole esistenti nel testo "b".
Ho crecato di lavorare con vettori, ma non riescoa capire perchè non funziona!
Vi allego il codice che ho scritto
import java.io.*;
import java.util.*;
public class provolone {
public static void main(String[] args) throws IOException {
String nextStr = null;
BufferedReader filebuf =
new BufferedReader(new FileReader("c:\\ortografia.txt"));
nextStr = filebuf.readLine();
StringTokenizer st = new StringTokenizer(nextStr);
int numero = st.countTokens();
String[] vett_orto = new String[numero];
int i = 0;
while (st.hasMoreTokens()) {
vett_orto[i] = st.nextToken();
i++;
}
String nextStr2 = null;
BufferedReader filebuf2 =
new BufferedReader(new FileReader("c:\\scrivimi.txt"));
nextStr2 = filebuf2.readLine();
StringTokenizer st2 = new StringTokenizer(nextStr2);
int numeros = st2.countTokens();
String[] vett_sorg = new String[numeros];
int j = 0;
while (st2.hasMoreTokens()) {
vett_sorg[j] = st2.nextToken();
j++;
}
int s = 0;
String[] vett = new String[vett_sorg.length];
/*boolean non_trovata = true;
for (int k = 0; k < vett_sorg.length; ++k) {
for (int t=0; t < vett_orto.length; ++t) {
non_trovata = true;
if (vett_sorg[k].compareToIgnoreCase(vett_orto[t])==0) {
non_trovata = false;
break;
}
}
if (non_trovata = true) {
vett[s] = vett_sorg[k];
++s;
}
}*/
int k=0;
boolean consentita = false;
for( k=0; k<vett_sorg.length; k++) {
for(int t=0; t<vett_orto.length; t++)
if(vett_sorg[k].compareToIgnoreCase(vett_orto[t])==0) {
consentita = true;
break;
}
}
if(consentita = false) {
System.out.println("La parola " + vett_sorg[k] + " non è consentita!");
}
consentita = false;
}
}