IvaAnd

StreamOfLetters

Mar 18th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.33 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3.  
  4. public class SteamOfLetters {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String command = "";
  8.         int counterC = 0;
  9.         int counterO = 0;
  10.         int counterN = 0;
  11.         char nextLetter = 0;
  12.  
  13.         while (!command.equals("End")) {
  14.  
  15.             command = scanner.nextLine();
  16.  
  17.             if (command.equals("End")) {
  18.                 break;
  19.             }
  20.             nextLetter = command.charAt(0);
  21.             if (nextLetter > 'a' && nextLetter < 'z' || nextLetter > 'A' && nextLetter < 'Z') {
  22.  
  23.                 if (counterC < 1 && nextLetter == 'c') {
  24.                     counterC++;
  25.                     continue;
  26.                 } else if (counterO < 1 && nextLetter == 'o') {
  27.                     counterO++;
  28.                     continue;
  29.                 } else if (counterN < 1 && nextLetter == 'n') {
  30.                     counterN++;
  31.                     continue;
  32.                 }
  33.  
  34.                 if (counterC == 1 && counterN == 1 && counterO == 1) {
  35.                     System.out.print(" ");
  36.                     counterC = 0;
  37.                     counterN = 0;
  38.                     counterO = 0;
  39.                 }
  40.                 System.out.print(nextLetter);
  41.             }
  42.         }
  43.     }
  44. }
Add Comment
Please, Sign In to add comment