问题描述
根据https://alexn.org/blog/2020/05/26/scala-fatal-warnings.html
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class WordsstartingWithCapitalLetter {
public static void main(String[] args) {
// Test 1 -- simple sentence
String s = "The Quick brown Fox jumps over the lazy Dog";
System.out.println("\ninput string: " + s);
System.out.println("capitalized words:" + getCountOfWordsWithInitialCap(s));
// Test 2 -- punctuation and newlines
s = "Lorem ipsum dolor sit amet,consectetur adipiscing elit,sed do eiusmod tempor\n"
+ "incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,quis nostrud exercitation\n"
+ "ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit\n"
+ "in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat\n"
+ "non proident,sunt in culpa qui officia deserunt mollit anim id est laborum.";
System.out.println("\ninput string: " + s);
System.out.println("capitalized words:" + getCountOfWordsWithInitialCap(s));
// Test 3 -- Scottish sirnames and hyphens
s = "The quick brown MacGavin jumps over the lazy MacGowan-dog";
System.out.println("\ninput string: " + s);
System.out.println("capitalized words:" + getCountOfWordsWithInitialCap(s));
}
private static final Pattern WORD_WITH_CAP_REGEX = Pattern.compile("([A-Z][-A-Za-z]*)");
private static int getCountOfWordsWithInitialCap(String s) {
int count = 0;
Matcher matcher = WORD_WITH_CAP_REGEX.matcher(s);
while(matcher.find()) {
count++;
String capitalizedWord = matcher.group(1);
System.out.println("\t"+count+" : "+capitalizedWord); // remove if you don't want to see the matches
}
return count;
}
}
将警告转化为错误,弃用除外。但它给出了这个:
"-Wconf:cat=deprecation:ws,any:e"
哪里
[error] bad option: '-Wconf:cat=deprecation:ws,any:e'
[error] (Compile / compileIncremental) Compilation Failed
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)