Advertisement
stoyanoff

StreamOfLetters

Sep 12th, 2020
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.36 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class StreamOfLetters {
  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.  
  18.             if (countC == 1 && countN == 1 && countO == 1) {
  19.                 System.out.print(finalWord + " ");
  20.                 countC = 0;
  21.                 countN = 0;
  22.                 countO = 0;
  23.                 finalWord = "";
  24.             }
  25.             // End cycle command
  26.             if (input.equals("End")) {
  27.                 isEndOf = true;
  28.                 continue;
  29.  
  30.             }
  31.             // Checking a-z A-Z
  32.             if (input.matches("^[a-zA-Z]*$")) {
  33.  
  34.                 if (input.charAt(0) == 'c' && countC == 0) {
  35.                     countC++;
  36.                     continue;
  37.                 } else if (input.charAt(0) == 'n' && countN == 0) {
  38.                     countN++;
  39.                     continue;
  40.                 } else if (input.charAt(0) == 'o' && countO == 0) {
  41.                     countO++;
  42.                     continue;
  43.                 }
  44.  
  45.                 finalWord += input.charAt(0);
  46.  
  47.             }
  48.  
  49.         }
  50.  
  51.  
  52.     }
  53.  
  54. }
  55.  
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement