Write a Java program to capitalize the first letter of each word in a sentence.
/*
Write a Java program to capitalize the first letter of each word in a
sentence.
Sample Output:
Input a Sentence: the quick brown fox jumps over the lazy dog.
The Quick Brown Fox Jumps Over The Lazy Dog.
*/
import java.util.*;
class Fifteen
{
public static void main(String arg[])
{
Scanner in = new Scanner(System.in);
System.out.print("\n Enter String hear: ");
String str = in.nextLine();
str = " " + str;
String s = "";
for(int i=0; i<str.length(); i++)
{
char ch = str.charAt(i);
if(ch == ' ')
{
s = s + ch;
i++;
ch = str.charAt(i);
s = s + Character.toUpperCase(ch);
}
else
{
s = s + ch;
}
}
s = s.trim();
System.out.println("\n "+s);
}
}
More Information on our channel Programmer Community
please like , share and subscribe to get notifications of new videos....
To understand this program video will coming soon on our you tube channel

Comments
Post a Comment