Advertisement
CoineTre

JF-ExcMethods02.Vowels Count

Feb 5th, 2021
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Exc2VowelsCount {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         String input = scanner.nextLine();
  7.         input = input.toLowerCase();
  8.         System.out.println(vowelsCount(input));
  9.     }
  10.  
  11.     private static int vowelsCount(String input) {
  12.         int count = 0;
  13.         for (int i = 0; i < input.length(); i++) {
  14.             if (input.charAt(i)== 'a' || input.charAt(i)==('e')
  15.                     ||input.charAt(i)==('i')
  16.                     ||input.charAt(i)==('o')
  17.                     || input.charAt(i)==('u'))
  18.             {
  19.                 count++;
  20.             }
  21.             }
  22.        return count;
  23.     }
  24. }
  25. //Write a method that receives a single string and prints the count of the vowels. Use appropriate name for the method.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement