這是我到目前爲止有:在Java中,如何創建一個簡單的程序來打印短語中輔音和元音的數量?
System.out.println("CONSONANT AND VOWEL COUNTER: Please type a phrase: ");
String lastPhrase = keyboard.nextLine();
int countCon = 0;
int countVow = 0;
if (lastPhrase.contains("bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ")) {
countVow++;
}
if (lastPhrase.contains("abcdefghijklmnopqrstuvwxyzABCDEFGHJKLIMNOPQRSTUVWXYZ")) {
countCon++;
}
System.out.println("There are " + countVow + " vowels and " + countCon + " consonants.");
它配備了0這兩個值。有什麼問題?
你在問'lastPhrase'是否包含這些長字符串。可以? – 2014-09-30 02:56:38
您將需要'loop'和'charAt()'。 – 2014-09-30 02:57:52