stoyanoff

Letters

Jul 6th, 2020
1,472
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.32 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class StreamOfLetters_03 {
  4.     public static void main(String[] args) {
  5.         Scanner myScan = new Scanner(System.in);
  6.  
  7.         String finalWord = "";
  8.         int countC = 0;
  9.         int countO = 0;
  10.         int countN = 0;
  11.         boolean isEndOf = false;
  12.         String input = "";
  13.  
  14.  
  15.         while (!isEndOf) {
  16.             input = myScan.nextLine();
  17.             if (input.equals("End")) {
  18.                 isEndOf = true;
  19.  
  20.             }
  21.             if (input.matches("^[a-zA-Z]*$")) {
  22.                 if (input.charAt(0) == 'c' && countC == 0) {
  23.                     countC++;
  24.                     continue;
  25.                 }
  26.                 if (input.charAt(0) == 'n' && countN == 0) {
  27.                     countN++;
  28.                     continue;
  29.                 }
  30.                 if (input.charAt(0) == 'o' && countO == 0) {
  31.                     countO++;
  32.                     continue;
  33.                 }
  34.                 if (countC == 1 && countN == 1 && countO == 1) {
  35.                     countC = 0;
  36.                     countN = 0;
  37.                     countO = 0;
  38.                     System.out.print(finalWord + " ");
  39.                     finalWord = "";
  40.  
  41.                 }
  42.                 finalWord += input.charAt(0);
  43.  
  44.  
  45.             }
  46.  
  47.  
  48.         }
  49.  
  50.     }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment