Advertisement
Guest User

Untitled

a guest
Oct 5th, 2019
1,619
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.70 KB | None | 0 0
  1. package com.company.WhileLoopMoreExercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class StreamOfLetters {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String command = scanner.nextLine();
  9.         boolean findC = false;
  10.         boolean findO = false;
  11.         boolean findN = false;
  12.         StringBuilder word = new StringBuilder();
  13.         while (!"End".equals(command)) {
  14.             char a = command.charAt(0);
  15.             if (((int) a >= 97 && (int) a <= 122) || ((int) a >= 65 && (int) a <= 90)) {
  16.                 switch (String.valueOf(a)) {
  17.                     case "c":
  18.                         if(!findC){
  19.                             findC = true;
  20.                             a = ' ';
  21.                         }
  22.                         break;
  23.                     case "o":
  24.                         if(!findO){
  25.                             findO = true;
  26.                             a = ' ';
  27.                         }
  28.                         break;
  29.                     case "n":
  30.                         if(!findN){
  31.                             findN = true;
  32.                             a = ' ';
  33.                         }
  34.  
  35.                         break;
  36.                 }
  37.                 word.append(a);
  38.                 if(findC && findO && findN){
  39.                     findC = false;
  40.                     findN = false;
  41.                     findO = false;
  42.                     String w = word.toString();
  43.                     w = w.replaceAll("\\s", "");
  44.                     System.out.printf("%s ",w);
  45.                     word.setLength(0);
  46.                 }
  47.  
  48.             }
  49.  
  50.  
  51.             command = scanner.nextLine();
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement