Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Arrays;
- import java.util.Scanner;
- public class SteamOfLetters {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String command = "";
- int counterC = 0;
- int counterO = 0;
- int counterN = 0;
- char nextLetter = 0;
- while (!command.equals("End")) {
- command = scanner.nextLine();
- if (command.equals("End")) {
- break;
- }
- nextLetter = command.charAt(0);
- if (nextLetter > 'a' && nextLetter < 'z' || nextLetter > 'A' && nextLetter < 'Z') {
- if (counterC < 1 && nextLetter == 'c') {
- counterC++;
- continue;
- } else if (counterO < 1 && nextLetter == 'o') {
- counterO++;
- continue;
- } else if (counterN < 1 && nextLetter == 'n') {
- counterN++;
- continue;
- }
- if (counterC == 1 && counterN == 1 && counterO == 1) {
- System.out.print(" ");
- counterC = 0;
- counterN = 0;
- counterO = 0;
- }
- System.out.print(nextLetter);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment