Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (7k points)

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?

1 Answer

0 votes
by (13.1k points)

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));

}

}

 Want to learn Java? Check out the Java certification from Intellipaat. 

Related questions

0 votes
2 answers
+3 votes
2 answers
0 votes
1 answer
asked Apr 13, 2021 in Java by sheela_singh (9.5k points)
0 votes
1 answer
asked Mar 6, 2021 in Java by dante07 (13.1k points)
0 votes
1 answer

Browse Categories

...