MiniMi2022

Stream Of Letters

Apr 7th, 2023
553
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.27 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.         int counterC = 0;
  7.         int counterO = 0;
  8.         int counterN = 0;
  9.         String word = "";
  10.         String secretWord = "";
  11.         String input = mySCan.nextLine();
  12.         while (!input.equals("End")) {
  13.             char letter = input.charAt(0);
  14.             if (letter >= 'a' && letter <= 'z' || letter >= 'A' && letter <= 'Z') {
  15.                 if (input.equals("c") && counterC == 0) {
  16.                     counterC++;
  17.                 } else if (input.equals("o") && counterO == 0) {
  18.                     counterO++;
  19.                 } else if (input.equals("n") && counterN == 0) {
  20.                     counterN++;
  21.                 } else {
  22.                     word += letter;
  23.                 }
  24.                 if (counterC + counterN + counterO == 3) {
  25.                     secretWord += word;
  26.                     secretWord += ' ';
  27.                     word = "";
  28.                     counterO = 0;
  29.                     counterC = 0;
  30.                     counterN = 0;
  31.                 }
  32.  
  33.             }
  34.             input = mySCan.nextLine();
  35.         }
  36.         System.out.println(secretWord);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment