Convert first letter to capital letter in java
import javax.xml.transform.stax.StAXSource;
class firstupper{
public static String capital(String str){
StringBuilder strbuild=new StringBuilder();
char ch=Character.toUpperCase(str.charAt(0));
strbuild.append(ch);
for(int i=1;i<str.length();i++){
if(str.charAt(i)==' '&&i<str.length()-1){
strbuild.append(str.charAt(i));
i++;
strbuild.append(Character.toUpperCase(str.charAt(i)));
}
else{
strbuild.append(str.charAt(i));
}
}
return strbuild.toString();
}
public static void main(String[] args) {
String str="hi i am udit ";
String capital=capital(str);
System.out.println(capital);
}
}
Comments
Post a Comment