andrei_gavrila

MIP-02-Tema-01-MinTwoVowels

Oct 20th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package net.forlornly;
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.util.Scanner;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class MinTwoVowels {
  10.  
  11.     /**
  12.      * @param args
  13.      */
  14.     public static void main(String[] args) {
  15.  
  16.         try {
  17.             Scanner scanner = new Scanner(new File("input.txt"));
  18.  
  19.             scanner.useDelimiter("[ ,\n\r]");
  20.  
  21.             Pattern pattern = Pattern.compile("[aeiou]{1}");
  22.  
  23.             while (scanner.hasNext()) {
  24.                 String s = scanner.next();
  25.  
  26.                 int count = 0;
  27.  
  28.                 Matcher matcher = pattern.matcher(s);
  29.  
  30.                 while (matcher.find()) {
  31.                     count++;
  32.                 }
  33.  
  34.                 if (count >= 2) {
  35.                     System.out.println("Cuvant cu " + count + " vocale (mai mult de doua inclusiv): " + s);
  36.                 }
  37.             }
  38.  
  39.             scanner.close();
  40.         } catch (FileNotFoundException e) {
  41.             e.printStackTrace();
  42.         }
  43.     }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment