Deiancom

Stream of letters

Feb 14th, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.11 KB | None | 0 0
  1. package ProgrammingBasics.WhileLoop;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class E03StreamOfLetters {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         StringBuilder word = new StringBuilder();
  9.         boolean c = false;
  10.         boolean o = false;
  11.         boolean n = false;
  12.         String input = scanner.nextLine();
  13.         while (!input.equals("End")) {
  14.             char letter = input.charAt(0);
  15.             if (Character.isLetter(letter)) {
  16.                 if (letter == 'c' && !c) {
  17.                     c = true;
  18.                 } else if (letter == 'o' && !o) {
  19.                     o = true;
  20.                 } else if (letter == 'n' && !n) {
  21.                     n = true;
  22.                 } else {
  23.                     word.append(letter);
  24.                 }
  25.             }
  26.             input = scanner.nextLine();
  27.             if (c && o && n) {
  28.                 System.out.print(word + " ");
  29.                 c = false;
  30.                 o = false;
  31.                 n = false;
  32.                 word = new StringBuilder();
  33.             }
  34.         }
  35.     }
  36. }
Add Comment
Please, Sign In to add comment