public void change(int n){
s2=(s1.substring(0.1)).toUpperCase();
for(int i=0;i<s.length;i++){
if(s.charAt(i)==' '){
c=s1.charAt(i+1);
u=Character.toUpperCase(u);
int n=i+1;
s.charAt***(n)***=u;
}
}
}
粗体部分给出了问题。 事情是这样的:- 意想不到的类型 必需:变量 发现:值
试试这个:
public static String capitalizeWords(String input) {
String[] words = input.split("\\s+"); // Split the input sentence into words
StringBuilder result = new StringBuilder();
for (String word : words) {
if (!word.isEmpty()) {
char firstChar = Character.toUpperCase(word.charAt(0));
result.append(firstChar).append(word.substring(1)).append(" ");
}
}
// Remove the trailing space and return the result
return result.toString().trim();
}