Advertisement
CarmenPop

Untitled

Feb 21st, 2020
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. public static void main(String[] args) {
  2. Scanner scanner = new Scanner(System.in);
  3. String c = "c";
  4. String o = "o";
  5. String n = "n";
  6. String word = "";
  7. int countc = 0;
  8. int counto = 0;
  9. int countn = 0;
  10. while(true){
  11. String letter = scanner.nextLine();
  12. if(letter.equals("End")){
  13. break;
  14. }
  15. if(letter.equals(c)){
  16. if (countc == 0){
  17. countc++;
  18. }else if(countc == 1){
  19. word = word + letter;
  20. }
  21. }else if(letter.equals(o)){
  22. if (counto == 0){
  23. counto++;
  24. }else if(counto == 1){
  25. word = word + letter;
  26. }
  27. }else if(letter.equals(n)){
  28. if (countn == 0){
  29. countn++;
  30. }else if(countn == 1){
  31. word = word + letter;
  32. }
  33. }else{
  34. word = word + letter;
  35. }
  36. if (countc ==1 && counto == 1 && countn == 1) {
  37. System.out.println(word + " ");
  38. countc = 0;
  39. counto = 0;
  40. countn = 0;
  41. word = "";
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement