
program to input a string and display the string with the first character of every word in upper case

import java.io.*;
import java.util.*;
public class FirstLetter {
public static String capitalizeFirstLetter(String str) {
final StringTokenizer st = new StringTokenizer(str, " ", true);
final StringBuilder sb = new StringBuilder();
while (st.hasMoreTokens()) {
String token = st.nextToken();
Character ch = Character.valueOf(token.charAt(0));
token = String.format("%s%s", Character
.toUpperCase(token.charAt(0)), token.substring(1));
sb.append(token);
}
return sb.toString();
}
public static void main(String[] args) throws Exception {
System.out.print("Enter the sentence : ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String inputString = br.readLine();
FirstLetter letter = new FirstLetter();
String words = letter.capitalizeFirstLetter(inputString);
System.out.println(words);
}
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.