dimanche 31 août 2014

How to use hasNextInt for this code?


Vote count:

0




Okay so the problem is to write a program that will identify vowels from consonant. I need to use Scanner and has Next()


the output should look like this


Enter a letter: a a is vowel Enter a letter: b b is consonant Enter a letter: 1 1 is invalid input


it will keep reading until it reaches the end of file professor hinted to use has Next Int because it will return false when there is no input


So here is what i have so far



public static void main (String[] args){
Scanner input = new Scanner(System.in);

boolean vowel = true;

do {
System.out.print("Enter a letter: ");
char letter = input.nextLine( ).charAt(0);

if (letter=='a'||letter=='A'||letter=='e'||letter=='E'||letter=='i'||letter=='I'||letter=='o'||letter=='O'||letter=='u'||letter=='U'){
System.out.println(letter + " is a vowel");

}
else if(Character.isLetter(letter)){
System.out.println(letter + " is a consonant");

}
else {
System.out.println(letter + " is an invalid input");

}
}
while(vowel);


}
}


asked 30 secs ago







How to use hasNextInt for this code?

Aucun commentaire:

Enregistrer un commentaire