i want to write this code as a vowel finder that exclude number and sign or symbol is there a better way beside add them one by one ? the code is working fine but i think there is a better way to do this . I'm new to java i just learn in 2 week ago.
import java.util.Scanner;
public class ConsonantOrVowel {
public static void main(String[] args) {
char c;
System.out.println("Please Input a Character: ");
Scanner input = new Scanner(System.in);
c=input.next().charAt(0);
if(c == '1'|| c == '2'|| c == '3'|| c == '4'|| c == '5' ||c == '6' ||c == '7'||c == '8'||c == '9'|| c == '!'|| c == '@' ||c == '#' ||c == '$'||c == '%'||c == '^'|| c == '&'|| c == '*' ||c == '(' ||c == ')'||c == '_'||c == '+'|| c == '-'|| c == '/'||c == '['|| c == ']'|| c == '{' ||c == '}' ||c == ';'||c == ':'||c == '"'|| c == ','|| c == '.'|| c == '?'){
System.out.println("Invalid Input");
}
else if(c == 'A'|| c == 'a'|| c == 'E' ||c == 'e' ||c == 'I'||c == 'i'||c == 'O'||c == 'o'||c == 'U'||c == 'u') {
System.out.println("Input Character is a Vowel");
}
else
System.out.println("Input Character is a Consonant");
}
}
Aucun commentaire:
Enregistrer un commentaire