Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class StreamOfLetters_03 {
- public static void main(String[] args) {
- Scanner myScan = new Scanner(System.in);
- String finalWord = "";
- int countC = 0;
- int countO = 0;
- int countN = 0;
- boolean isEndOf = false;
- String input = "";
- while (!isEndOf) {
- input = myScan.nextLine();
- if (input.equals("End")) {
- isEndOf = true;
- }
- if (input.matches("^[a-zA-Z]*$")) {
- if (input.charAt(0) == 'c' && countC == 0) {
- countC++;
- continue;
- }
- if (input.charAt(0) == 'n' && countN == 0) {
- countN++;
- continue;
- }
- if (input.charAt(0) == 'o' && countO == 0) {
- countO++;
- continue;
- }
- if (countC == 1 && countN == 1 && countO == 1) {
- countC = 0;
- countN = 0;
- countO = 0;
- System.out.print(finalWord + " ");
- finalWord = "";
- }
- finalWord += input.charAt(0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment