Back

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

I am using Java to get string input from the user. I want to make the first letter of this input capitalized.

Can somebody help me with this?

1 Answer

0 votes
by (13.1k points)

You can use .substring() and .toUpperCase() like this:

public static void main(String[] args) throws IOException {

    BufferedReader bufferedreader = new BufferedReader(new InputStreamReader(System.in));

    // Actually use the Reader

    String name = bufferedreader.readLine();

    // Don't mistake String object with a Character object

    String s1 = name.substring(0, 1).toUpperCase();

    String nameCapitalized = s1 + name.substring(1);

    System.out.println(nameCapitalized);

}

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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

29.3k questions

30.6k answers

501 comments

104k users

Browse Categories

...