-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToUpperCase.java
More file actions
31 lines (24 loc) · 829 Bytes
/
Copy pathToUpperCase.java
File metadata and controls
31 lines (24 loc) · 829 Bytes
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
package strings;
public class ToUpperCase {
public static String upperCase(String str) {
StringBuilder sb = new StringBuilder("");
char ch = Character.toUpperCase(str.charAt(0));
sb.append(ch);
for (int i = 1; i < str.length(); i++) {
if (str.charAt(i) == ' ' && i < str.length() - 1) {
sb.append(str.charAt(i));
i++;
sb.append(Character.toUpperCase(str.charAt(i)));
} else {
sb.append(str.charAt(i));
}
}
return sb.toString();
}
public static void main(String[] args) {
String str = "hello, it's Jomon";
System.out.println(upperCase(str));
}
}
// For a given String convert the first letter of each world to uppercase.
// "hello, it's Jomon"