朗读句子,仅打印出同一字母连续重复3次以上的单词

问题描述

我想制作一个程序,其中仅重复背靠背重复包含3个相同字母的单词。例如,穿越山脉的mooonkey raaan。该程序只应重复mooonkey,raaan

public class Triplets2 {

public static void main(String[] args) {

    Scanner input = new Scanner(System.in);
    System.out.println("write a sentence");
    String in = input.nextLine();
    
    String [] sentence = in.split(" ");
    
    for (int i = 0; i < sentence.length; i++) {
        
        char [] word = sentence[i].toCharArray();
        int counter =0;
        
        for (int s = 0; s < word.length; s++) {
            
            char letter = word[s];
            
            for (int x = 0; x<word.length; x++) {
                
                if (letter == word[x]) {
                    counter++;
                }
                    else {
                        counter = 0;
                }
            }
        }
        if (counter >=3) {
            System.out.print(sentence[i] + ",");
        }
    }
}

该程序只是不重复任何内容。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)