public static String strCap(String str){
//capitalizes the first letter of the string
String newStr1 = str.replace(str.charAt(0), Character.toUpperCase(str.charAt(0)));
int position = str.indexOf(". "); // looks for a period followed by a space
while(position != -1){
newStr1 = newStr1.replace(newStr1.charAt(position + 2), Character.toUpperCase(newStr1.charAt(position + 2)));
position = str.indexOf(". ", position+1);
}
return newStr1;
}
the user types in a string and the program capitalizes where necessary. the first letter of the sentence is taken care of, but the rest i think it's perfect, but it's not working. i can't figure out what's wrong with this method i have here. it gives me weird results sometimes like this: DSf DSf. SDf SDf.