Advertisement
kolevra

pbWhileStreamOfLetters

Feb 6th, 2023
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.38 KB | None | 0 0
  1. package PBMoreExercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class moreWhile03StreamLetters {
  6.     public static void main(String[] args) {
  7.  
  8.         Scanner scanner = new Scanner(System.in);
  9.  
  10.         String input = "";
  11.         int cSymbol = 0;
  12.         int oSymbol = 0;
  13.         int nSymbol = 0;
  14.         String wordBySteps = "";
  15.  
  16.         while (!input.equals("End")) {
  17.  
  18.              if (cSymbol == 1 && oSymbol == 1 && nSymbol == 1) {
  19.  
  20.                 System.out.printf("%s ", wordBySteps);
  21.                 wordBySteps = "";
  22.                 cSymbol = 0;
  23.                 oSymbol = 0;
  24.                 nSymbol = 0;
  25.                 continue;
  26.             }
  27.  
  28.             input = scanner.nextLine();
  29.  
  30.             if (input.equals("c") && cSymbol == 0) {
  31.                 cSymbol++;
  32.                 continue;
  33.             } else if (input.equals("o") && oSymbol == 0) {
  34.                 oSymbol++;
  35.                 continue;
  36.             } else if (input.equals("n") && nSymbol == 0) {
  37.                 nSymbol++;
  38.                 continue;
  39.             }
  40.  
  41.             char currentSymbol = input.charAt(0);
  42.  
  43.             if (Character.isLetter(currentSymbol)) {
  44.  
  45.                 wordBySteps = wordBySteps + currentSymbol;
  46.  
  47.             }
  48.  
  49.         }
  50.  
  51.         if (cSymbol == 1 && oSymbol == 1 && nSymbol == 1) {
  52.             System.out.printf("%s ", wordBySteps);
  53.         }
  54.  
  55.     }
  56. }
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement