Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String c = "c";
- String o = "o";
- String n = "n";
- String word = "";
- int countc = 0;
- int counto = 0;
- int countn = 0;
- while(true){
- String letter = scanner.nextLine();
- if(letter.equals("End")){
- break;
- }
- if(letter.equals(c)){
- if (countc == 0){
- countc++;
- }else if(countc == 1){
- word = word + letter;
- }
- }else if(letter.equals(o)){
- if (counto == 0){
- counto++;
- }else if(counto == 1){
- word = word + letter;
- }
- }else if(letter.equals(n)){
- if (countn == 0){
- countn++;
- }else if(countn == 1){
- word = word + letter;
- }
- }else{
- word = word + letter;
- }
- if (countc ==1 && counto == 1 && countn == 1) {
- System.out.println(word + " ");
- countc = 0;
- counto = 0;
- countn = 0;
- word = "";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement