Back
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?
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);}
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.
31k questions
32.8k answers
501 comments
693 users