Guidewire online assessment question codility
Anonymous User
490

Given string split the sentense based on dot(".") , question mark ("?") or exclamatory ("!").
Count how many words in the string and return the max number of word in the given String.

public int solution(String S) {
        if (S == null)
            return 0;
        if (S.trim().length() == 0)
            return 0;
        int count = 0;
        for (String dotSplit : S.split("\\.")) {
            for (String senQSplit : dotSplit.split("\\?")) {
                for (String splitExcla : senQSplit.split("!")) {
                    int curCnt = 0;
                    for (String word : splitExcla.split(" ")) {
                        if (word != null && word.trim().length() != 0) {
                            curCnt += 1;
                        }
                    }
                    count = Math.max(count, curCnt);
                }
            }
        }
        return count;

    }
	```
Comments (0)