为什么以下算法不会停止?(str是我正在搜索的字符串,findStr是我想要查找的字符串)
String str = "helloslkhellodjladfjhello";
String findStr = "hello";
int lastIndex = 0;
int count = 0;
while (lastIndex != -1) {
lastIndex = str.indexOf(findStr,lastIndex);
if( lastIndex != -1)
count++;
lastIndex += findStr.length();
}
System.out.println(count);
Run Code Online (Sandbox Code Playgroud) 这可能看起来像一个愚蠢的问题,但经过谷歌的网页,我已经能够找到我想要的答案.
s1.setName(JOptionPane.showInputDialog("Enter Name: ");
Run Code Online (Sandbox Code Playgroud)
对于上面的代码,如何将用户输入的数据格式化为所有大写字母?
任何帮助在这里将不胜感激.