Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gitaficionado/73089f4deea2029f535bfb4c828e214c to your computer and use it in GitHub Desktop.
Save gitaficionado/73089f4deea2029f535bfb4c828e214c to your computer and use it in GitHub Desktop.
(Count vowels and consonants) Assume letters A,E,I,O, and U as the vowels. Write a program that prompts the user to enter a string and displays the number of vowels and consonants in the string
import java.util.Scanner;
public class CountVowelsAndConsonantsExercise_05_49 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter a string: ");
//Create string input form user
_____________________________
int countVowels = __;
int countConsonants = __;
for (int i = 0; i < s.length(); i++) {
__________ temp = Character.toUpperCase(s.charAt(i));
if (temp == '__' || temp == '__' || temp == '___' || temp == '__' || temp == '__')
___________________;
else if (Character.isLetter(temp))
countConsonants++;
}
System.out.println("The number of vowels is " + ____________);
System.out.println("The number of consonants is " + _________________);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment