相关疑难解决方法(0)

字符串中子字符串的出现

为什么以下算法不会停止?(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)

java string

117
推荐指数
11
解决办法
30万
查看次数

将用户输入字符串转换为大写Java

这可能看起来像一个愚蠢的问题,但经过谷歌的网页,我已经能够找到我想要的答案.

s1.setName(JOptionPane.showInputDialog("Enter Name: ");
Run Code Online (Sandbox Code Playgroud)

对于上面的代码,如何将用户输入的数据格式化为所有大写字母?

任何帮助在这里将不胜感激.

java user-input uppercase

7
推荐指数
2
解决办法
3万
查看次数

标签 统计

java ×2

string ×1

uppercase ×1

user-input ×1