-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakeAllLetterUpperInAString.java
More file actions
40 lines (34 loc) · 1.43 KB
/
MakeAllLetterUpperInAString.java
File metadata and controls
40 lines (34 loc) · 1.43 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
29
30
31
32
33
34
35
36
37
38
39
40
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/*
Написать программу, которая вводит с клавиатуры строку текста.
Программа заменяет в тексте первые буквы всех слов на заглавные.
Вывести результат на экран.
*/
public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String string = reader.readLine();
String gap = " ";
List<Character> charList = new ArrayList<>();
for (int i = 0; i < string.length(); i++) {
charList.add(string.charAt(i));
}
for (int i = 0; i < charList.size() - 1; i++) {
if (charList.get(i).equals(gap.charAt(0)) && !charList.get(i + 1).equals(gap.charAt(0))) {
charList.set(i + 1, Character.toUpperCase(charList.get(i + 1)));
}
if (i == 0 && !charList.get(i).equals(gap.charAt(0))) {
charList.set(i, Character.toUpperCase(charList.get(i)));
}
}
StringBuilder output = new StringBuilder();
for (int i = 0; i < charList.size(); i++) {
output.append(charList.get(i));
}
System.out.println(output);
}
}