Advertisement
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 scan = new Scanner(System.in);
- int countC = 0;
- int countO = 0;
- int countN = 0;
- String word = "";
- char letter = Character.MIN_VALUE;
- String letterToPrint = "";
- String userInput = scan.nextLine();
- String wordToPrint = "";
- while (!(userInput.equals("End"))) {
- while (!(countC >= 1 && countN >= 1 && countO >= 1) && !(userInput.equals("End"))) {
- letter = userInput.charAt(0);
- if ((letter > 64 && letter < 91) || (letter > 96 && letter < 122)) {
- if (letter == 'c') {
- if (countC >= 1) {
- word = word + "c";
- }
- countC++;
- } else if (letter == 'o') {
- if (countO >= 1) {
- word += "o";
- }
- countO++;
- } else if (letter == 'n') {
- if (countN >= 1) {
- word = word + "n";
- }
- countN++;
- } else {
- letterToPrint = Character.toString(letter);
- word += userInput;
- }
- if (countC>=1 && countN>=1 && countO>=1) {
- word += " ";
- wordToPrint = word;
- }
- }
- userInput = scan.nextLine();
- }
- if (!(userInput.equals("End"))){
- countC = 0;
- countN = 0;
- countO = 0;
- }}
- System.out.println(wordToPrint);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement