Created
July 17, 2018 08:46
-
-
Save csr/0b9a604efbcfba7e115812ec2ba32c66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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