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