File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments