Advertisements
Advertisements
प्रश्न
Write a program for the following.
Input a String and change the text given by the user to title case. [avoid using method.toUpperCase()]
कोड लेखन
Advertisements
उत्तर
import java.util.*;
class clTask
{
void main()
{
String s1 = "", s2 = “", s3= "'";
Scanner sc = new Scanner(System.in);
char ch1, ch2;
int count = 0;
System.out.print(" Enter a sentence : ");
s1 = sc.nextLine();
for(int j = 0; j <= s1.length() - 1; j++)
{
ch1 = s1.charAt(j);
if(ch1 >='a' && ch1 <>=,z'(
{
s2 = s2 + (char)(ch1 – 32);
}
else
{
s2 = s2 + ch1;
}
}
System.out.println("New string is: " + s2);
}
}
Output:
Enter a sentence : Independence Day is on 15Aug1947
New string is : INDEPENDENCE DAY IS ON 15AUG1947
shaalaa.com
या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
