With for loop and if else statement I have already changed the initial character of words to upper case.
I would like to know how to store the value into the x variable so that it can return to main and print it out.
The output suppose to be "The Simpson Series" instead of "the simpson series". enter image description here
Thank you.
package tt5;
public class StringCharacter {
public static String capitalize(String x){
//check character length
for(int i=0; i<x.length(); i++){
Character temp = x.charAt(i);
boolean b1 = Character.isLetter(temp);
//change words to uppercase if condition matched
if(i==0){
String y = temp.toString();
String a = y.toUpperCase();
}
else if(b1==false){
temp = x.charAt(i+1);
String y = temp.toString();
String a = " " + y.toUpperCase();
i++;
}
else{
String a = temp.toString();
}
}
//return result
String a = "";
x = x.concat(a);
return x;
}
//input words and print the result
public static void main(String[] args){
String str = "the simpson series";
String total = capitalize(str);
System.out.println(total);
}
}