-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode4.txt
More file actions
28 lines (27 loc) · 1.05 KB
/
code4.txt
File metadata and controls
28 lines (27 loc) · 1.05 KB
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
import java.util.*;
class Codechef {
public static void main(String[] args) throws java.lang.Exception {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.nextLine();
for (int i = 0; i < n; i++) {
String s = sc.nextLine();
String[] words = s.split(" ");
for (int j = 0; j < words.length; j++) {
String firstLetter = words[j].substring(0, 1);
String restOfWord = words[j].substring(1);
if (firstLetter.equals(firstLetter.toUpperCase())) {
words[j] = firstLetter + restOfWord;
} else if(words[j].equals(words[j].toUpperCase())) {
words[j]=words[j];
}
else{
firstLetter = firstLetter.toUpperCase();
words[j] = firstLetter + restOfWord.toLowerCase();
}
}
String sen = String.join(" ", words);
System.out.println(sen);
}
}
}