-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCapitalize.java
More file actions
50 lines (33 loc) · 949 Bytes
/
Copy pathCapitalize.java
File metadata and controls
50 lines (33 loc) · 949 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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.*;
class Capitalize {
public static String LetterCapitalize(String str) {
char [] newStr = str.toCharArray();
//check if the string is null
if(newStr == null) {
return "";
}
int index = 0;
char capitalized;
//if it isnt, the capitalize the first word
while (index < str.length()) {
if(index == 0) {
capitalized = Character.toUpperCase(newStr[index]);
newStr[index] = capitalized;
}
//run thru the array and look for the spaces,
if(newStr[index] == ' '){
capitalized = Character.toUpperCase(newStr[++index]);
newStr[index] = capitalized;
}
index++;
}
String ret = new String(newStr);
return ret;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(LetterCapitalize(s.nextLine()));
s.close();
}
}