Professional Documents
Culture Documents
A.Y. 2023-24
ASSIGNMENT – 17
1. Write a program to accept a sentence from the user and convert the
first character of every word to uppercase.
import java.util.*;
public class StringCaseChange
{
public void stringConvert(String s)
{
s = " " + s;
String cs = "";
char ch;
for(int i = 0; i < s.length(); i++)
{
ch = s.charAt(i);
if(Character.isWhitespace(ch))
{
ch = Character.toUpperCase(s.charAt(i+1));
if(i!= 0)
cs = cs + " " + ch;
else
cs = cs + ch;
i++;
}
else
cs += ch;
}
System.out.println("The original string is: " +
s.trim());
Enter a sentence:
We are in a cyber world
The original string is: We are in a cyber world
The converted string is: We Are In A Cyber World