I'm trying to write a program that reads a String written by the user and checks if a word has only one type of vowel(for example: eye, wifi, cap...). I have one boolean for each vowel and when read a word, if the readen char is an 'e' I set the boolean itsE to true, and the same for the other vowels. The problem is that I thought that with an if and the condition: "if boolean itsE it's true and all the others are false, I print that word" but it never enters the if. Any suggestions?
Note: LT IS A GIVEN CLASS TO READ CHAR SEQUENCES
public class voweltype {
static final char BLANK=' ';
static final char FINAL='.';
static final int MAX=20;
static LT in= new LT();
static char caracter;
static char [] word=new char[MAX];
static int numchars;
public static void main(String[]args) throws Exception{
boolean itsA, itsE, itsI, itsO, itsU;
System.out.print("INTRODUCE your text: ");
char=in.readcharSequence();
while (char== BLANK) {
char= in.readcharSequence();
}
while(char!=FINAL){
numchars=0;
itsA=false;
itsE=false;
itsI=false;
itsO=false;
itsU=false;
while ((char!=FINAL)&&(char!=ESPACIO)) {
word[numchars]=char;
numchars++;
if(char=='a'){
itsA=true;
}
if(char=='e'){
itsE=true;
}
if(char=='i'){
itsI=true;
}
if(char=='o'){
itsO=true;
}
if(char=='u'){
itsU=true;
}
char=in.readcharSequence();
}
System.out.println();
System.out.println(itsA);
System.out.println(itsE);
System.out.println(itsI);
System.out.println(itsO);
System.out.println(itsU);
System.out.println("outside if");
if(((esA=true)&&(esE=false)&&(esI=false)&&(esO=false)&&(esU=false))||
((esA=false)&&(esE=true)&&(esI=false)&&(esO=false)&&(esU=false))||
((esA=false)&&(esE=false)&&(esI=true)&&(esO=false)&&(esU=false))||
((esA=false)&&(esE=false)&&(esI=false)&&(esO=true)&&(esU=false))||
((esA=false)&&(esE=false)&&(esI=false)&&(esO=false)&&(esU=true))){
System.out.println("inside if");
for(int i=0;i<numchars;i++){
System.out.print(word[i]);
}
System.out.println();
}
while (char== ESPACIO) {
char=in.readcharSequence();
}
}
}
}
Aucun commentaire:
Enregistrer un commentaire