deyanmalinov

4. Count Character Types

Apr 9th, 2020
245
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.io.BufferedReader;
  2. import java.io.FileNotFoundException;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5. public class Main {
  6.     public static void main(String[] args) throws IOException {
  7.         String path = "D:\\Coding\\BG_Softuni\\Java Advanced - January 2019" +
  8.                 "\\04.1. Java-Advanced-Files-and-Directories-Exercises\\" +
  9.                 "04. Java-Advanced-Files-and-Streams-Exercises-Resources\\input.txt";
  10.         BufferedReader reader = new BufferedReader(new FileReader(path));
  11.         int vouel = 0;
  12.         int conso = 0;
  13.         int punkt = 0;
  14.         try {
  15.             String line = reader.readLine();
  16.             while (line != null){
  17.                 char[] masv =line.toCharArray();
  18.                 for (char cha : masv) {
  19.                     if (cha == 'a' || cha == 'e' || cha == 'i' || cha == 'o' || cha == 'u'){
  20.                         vouel++;
  21.                     }else if (cha == '!' || cha == ',' || cha == '.' || cha == '?'){
  22.                         punkt++;
  23.                     }else if (cha == ' ') {
  24.                        
  25.                     }else   {
  26.                          conso++;
  27.                     }
  28.                 }
  29.                 line=reader.readLine();
  30.             }
  31.             System.out.printf("Vowels: %d\nConsonants: %d\nPunctuation: %d", vouel,conso,punkt);
  32.         } catch (FileNotFoundException e) {
  33.             e.printStackTrace();
  34.         } catch (IOException e) {
  35.             e.printStackTrace();
  36.         }
  37.     }
  38. }
RAW Paste Data