Advertisement
desislava_topuzakova

02. Vowels Count

Jun 13th, 2021
1,359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 KB | None | 0 0
  1. import java.util.Locale;
  2. import java.util.Scanner;
  3.  
  4. public class Demo {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String text = scanner.nextLine().toLowerCase();
  8.         printCountVowels(text);
  9.  
  10.     }
  11.  
  12.     //print count of vowels in text
  13.     private static void printCountVowels(String text) {
  14.         //1. обхожда текст (взимаме всички символи)
  15.         //2. проверка дали символа е гласна буква (a, e, i, o, u) -> увеличавам броя с 1
  16.         //3. принтирам броя на гласните букви
  17.  
  18.         int count = 0; //броя на гласните букви
  19.         for (int index = 0; index <= text.length() - 1; index++) {
  20.             char currentSymbol = text.charAt(index);
  21.             switch(currentSymbol) {
  22.                 case 'a':
  23.                 case 'e':
  24.                 case 'i':
  25.                 case 'o':
  26.                 case 'u':
  27.                     count++;
  28.                     break;
  29.             }
  30.         }
  31.         System.out.println(count);
  32.  
  33.     }
  34.  
  35.  
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement