countvowels.java

来自「《A first book of java》by Gary J.Bronson 」· Java 代码 · 共 29 行

JAVA
29
字号
import java.io.*;
public class CountVowels
{
  public static void main (String[] args) 
  {
    
    String str = new String("Counting the number of vowels");
    int i, numChars;
    int vowelCount = 0;

    System.out.println("The string: " + str);
    
    numChars = str.length();
    for (i = 0; i < numChars; i++)
    {
      switch(str.charAt(i))   // here is where a character is retrieved
      {
        case 'a': 
        case 'e': 
        case 'i': 
        case 'o': 
        case 'u':
          vowelCount++;   
      }
    }

    System.out.println("has " + vowelCount + " vowels.");
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?