Advertisement
kocev

Vowels

Feb 24th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.70 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Vowels {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         System.out.println("Enter a sentence:");
  7.         String line = scanner.nextLine();
  8.         int count = 0;
  9.         for (int i = 0; i < line.length(); i++) {
  10.             if ('a' == line.charAt(i)
  11.                     || 'o' == line.charAt(i)
  12.                     || 'u' == line.charAt(i)
  13.                     || 'e' == line.charAt(i)
  14.                     || 'i' == line.charAt(i)
  15.                     || 'y' == line.charAt(i)) {
  16.                 count++;
  17.             }
  18.         }
  19.         System.out.println("The number of vowels is " + count);
  20.     }
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement