Back
I want to convert the first character of a string into the upper case and the rest of the characters of the string into the lower case. How can I do this?
You can try this:
public class Main{public static String Convertoupperandlower(String s){ if(s.length()==0) return ""; else if(s.length()==1) return s.toUpperCase(); return s.substring(0,1).toUpperCase()+s.substring(1).toLowerCase();}public static void main(String[] args) {String s="bangalore";System.out.println(Convertoupperandlower(s));}}
public class Main
{
public static String Convertoupperandlower(String s){
if(s.length()==0)
return "";
else if(s.length()==1)
return s.toUpperCase();
return s.substring(0,1).toUpperCase()+s.substring(1).toLowerCase();
}
public static void main(String[] args) {
String s="bangalore";
System.out.println(Convertoupperandlower(s));
Want to learn Java? Check out the Java certification from Intellipaat.
31k questions
32.8k answers
501 comments
693 users