Advertisement
Gergana_Cisarova

Untitled

Jun 17th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class StreamOfLetters {
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6.  
  7. int countC = 0;
  8. int countO = 0;
  9. int countN = 0;
  10. String word = "";
  11. char letter = Character.MIN_VALUE;
  12. String letterToPrint = "";
  13. String userInput = scan.nextLine();
  14. String wordToPrint = "";
  15.  
  16.  
  17. while (!(userInput.equals("End"))) {
  18. while (!(countC >= 1 && countN >= 1 && countO >= 1) && !(userInput.equals("End"))) {
  19.  
  20. letter = userInput.charAt(0);
  21. if ((letter > 64 && letter < 91) || (letter > 96 && letter < 122)) {
  22. if (letter == 'c') {
  23. if (countC >= 1) {
  24. word = word + "c";
  25. }
  26. countC++;
  27. } else if (letter == 'o') {
  28. if (countO >= 1) {
  29. word += "o";
  30. }
  31. countO++;
  32. } else if (letter == 'n') {
  33. if (countN >= 1) {
  34. word = word + "n";
  35. }
  36. countN++;
  37. } else {
  38. letterToPrint = Character.toString(letter);
  39. word += userInput;
  40.  
  41. }
  42. if (countC>=1 && countN>=1 && countO>=1) {
  43. word += " ";
  44. wordToPrint = word;
  45. }
  46.  
  47. }
  48. userInput = scan.nextLine();
  49.  
  50. }
  51. if (!(userInput.equals("End"))){
  52. countC = 0;
  53. countN = 0;
  54. countO = 0;
  55.  
  56.  
  57. }}
  58.  
  59. System.out.println(wordToPrint);
  60.  
  61. }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement