Enter a string, is a string containing the contents of the articles in English punctuation and spaces. Output returns the maximum string length of the English word string.

package com.cm.activity.ss;

/**
 * @Author: machi
 * @Date: 2019-12-17
 * @Time: 17:46
 * @ClassName: LongestStatistics
 * @Description:输入一个字符串,字符串内容是一片含有标点符号和空格的英文文章。
 * 输出返回这个字符串长度最大的英文单词字符串。
 */
public class LongestStatistics {
    public static void main(String[] args) {
        String sss="sahfh jiosajfd safj,efjosi,heufih,ssf";
        String[] s= sss.trim().replace(","," ").replace("。"," ").split(" ");
        int max=0;
        String maxStr="";
        for (int i=0;i<s.length;i++){
            if (max<s[i].length()){
                max=s[i].length();
                maxStr=s[i];
            }

        }
        System.out.println(maxStr);
    }
}

He published 194 original articles · won praise 55 · views 50000 +

Guess you like

Origin blog.csdn.net/weixin_42470710/article/details/103585260