Skip to content

Instantly share code, notes, and snippets.

@csr
Created July 17, 2018 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csr/0b9a604efbcfba7e115812ec2ba32c66 to your computer and use it in GitHub Desktop.
Save csr/0b9a604efbcfba7e115812ec2ba32c66 to your computer and use it in GitHub Desktop.
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