Skip to content

Instantly share code, notes, and snippets.

@csr
Created Jul 17, 2018
Embed
What would you like to do?
public class DivideEtImperaVocali {
public DivideEtImperaVocali() {
char[] array = new char[]{'a', 'a', 'e', 'u', 'e', 'f', 'f'};
boolean result = vocaliPari(array, 0, array.length-1);
System.out.println("vocali pari? result:" + result);
}
public boolean vocaliPari(char[] array, int i, int f) {
if (i == f) {
return isVocale(array[i]);
}
int m = (i+f)/2;
boolean sx = vocaliPari(array, i, m);
boolean dx = vocaliPari(array, m+1, f);
return !(sx ^ dx); // XOR
}
public boolean isVocale(char carattere) {
char[] vocali = new char[]{'a', 'e', 'i', 'o', 'u'};
boolean isVocale = false;
for (int i = 0; i < vocali.length; i++) {
if (carattere == vocali[i]) {
System.out.println("si, e' una vocale:" + carattere);
isVocale = true;
}
}
return isVocale;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment