Skip to content

Commit a687cb8

Browse files
committed
Letter Capitalize
1 parent 63a3246 commit a687cb8

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/easy/LetterCapitalize.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package easy;
2+
3+
/**
4+
* Have the function LetterCapitalize(str) take the str parameter
5+
* being passed and capitalize the first letter of each word.
6+
* Words will be separated by only one space.
7+
*/
8+
public class LetterCapitalize {
9+
10+
/**
11+
* Letter Capitalize function.
12+
*
13+
* @param str input string
14+
* @return string with the letters capitalised
15+
*/
16+
private static String letterCapitalize(String str) {
17+
String[] splitWords = str.split(" ");
18+
for (int i = 0; i < splitWords.length; i++) {
19+
String word = splitWords[i];
20+
splitWords[i] = word.substring(0, 1).toUpperCase() + word.substring(1);
21+
}
22+
return String.join(" ", splitWords);
23+
}
24+
25+
/**
26+
* Entry point.
27+
*
28+
* @param args command line arguments
29+
*/
30+
public static void main(String[] args) {
31+
var result1 = letterCapitalize("The soul becomes dyed with the color of its thoughts.");
32+
System.out.println(result1);
33+
var result2 = letterCapitalize("The universe is change; our life is what our thoughts make it.");
34+
System.out.println(result2);
35+
}
36+
37+
}

0 commit comments

Comments
 (0)