-
Notifications
You must be signed in to change notification settings - Fork 0
/
String_Case.txt
35 lines (28 loc) · 902 Bytes
/
String_Case.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import java.util.Scanner;
class String_Case
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter a string :- ");
String str = sc.nextLine();
str = str.trim();
String SentenceCase = Character.toUpperCase(str.charAt(0)) + str.substring(1);
String TitleCase = "";
str = " " + str;
int length = str.length();
for(int i = 0 ; i < length ; ++i)
{
if(str.charAt(i) == ' ')
{
TitleCase += " ";
TitleCase += Character.toUpperCase(str.charAt(++i));
continue;
}
TitleCase += str.charAt(i);
}
TitleCase = TitleCase.trim();
System.out.println("\nSentence Case = " + SentenceCase);
System.out.println("Title Case = " + TitleCase);
}
}