<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Java 程序:計算字符串中的元音和輔音 > 原文: [https://beginnersbook.com/2019/04/java-program-to-count-vowels-and-consonants-in-a-string/](https://beginnersbook.com/2019/04/java-program-to-count-vowels-and-consonants-in-a-string/) 在本文中,我們將編寫一個 Java 程序來計算`String`中的元音和輔音。 ## 用于計算給定字符串中的元音和輔音的程序 這里我們有兩個變量`vcount`和`ccount`來分別保持元音和輔音的數量。我們已經使用[`toLowerCase()`方法](https://beginnersbook.com/2013/12/java-string-tolowercase-method-example/)將字符串的每個字符串轉換為小寫,以便于比較。 然后我們使用[`charAt()`方法](https://beginnersbook.com/2013/12/java-string-charat-method-example/)和[`if..else..if`](https://beginnersbook.com/2017/08/if-else-statement-in-java/)語句將字符串的每個字符串與元音`'a'`,`'e'`,`'i'`,`'o'`,`'u'`進行比較,如果找到匹配,那么我們正在增加元音計數器`vcount`,否則我們正在增加輔音計數器`ccount`。 ```java public class JavaExample { public static void main(String[] args) { String str = "BeginnersBook"; int vcount = 0, ccount = 0; //converting all the chars to lowercase str = str.toLowerCase(); for(int i = 0; i < str.length(); i++) { char ch = str.charAt(i); if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') { vcount++; } else if((ch >= 'a'&& ch <= 'z')) { ccount++; } } System.out.println("Number of Vowels: " + vcount); System.out.println("Number of Consonants: " + ccount); } } ``` **輸出:** ![Java program to count vowels and consonants in a String](https://img.kancloud.cn/28/9f/289f3d39da728ed4d66c17e00dbd0af7_932x1012.jpg) #### 相關的 Java 程序 1. [Java 程序:在字符串中查找字符的出現](https://beginnersbook.com/2019/04/java-program-to-find-the-occurrence-of-a-character-in-a-string/) 2. [Java 程序:對字符串執行冒泡排序](https://beginnersbook.com/2019/04/java-program-to-perform-bubble-sort-on-strings/) 3. [Java 程序:反轉一個字符串](https://beginnersbook.com/2017/09/java-program-to-reverse-a-string-using-recursion/) 4. [Java 程序:使用`Switch Case`檢查元音或輔音](https://beginnersbook.com/2017/09/java-program-to-check-vowel-and-consonant-using-switch-case/)
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看