Ci ho pensato un pò su, ecco la soluzione.
codice:
import java.util.*;
public class test3 {
//Questo programma individua le parole contenute in una stringa.
public static void main(String argv[]){
String testo = "Che bel forum quello che vedo";
String cerca ="foru vedo";
StringTokenizer testost = new StringTokenizer(testo);
StringTokenizer cercast = new StringTokenizer(cerca);
String [] A = new String[testost.countTokens()];
int i = 0;
while (testost.hasMoreTokens()){
A[i] = testost.nextToken();
i++;
}
boolean ok = true;
while ((cercast.hasMoreTokens())&&(ok)){
ok = trova(A, cercast.nextToken());
}
if (ok)
System.out.println("Test riuscito per " + cerca);
else
System.out.println("Test fallito per " + cerca);
}
private static boolean trova (String b[], String c){
int i = 0;
boolean trovato = false;
while ((i < b.length) && (trovato == false)){
if (b[i].equals(c))
trovato = true;
i++;
}
return trovato;
}
}