-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamelCase.java
More file actions
50 lines (35 loc) · 1.25 KB
/
Copy pathCamelCase.java
File metadata and controls
50 lines (35 loc) · 1.25 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
41
42
43
44
45
46
47
48
49
50
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
/*count the number of words in the camelcase string */
public class CamelCase {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String s = in.next();
int count = 0;
for(int i = 0; i < s.length(); i++) {
if(Character.isUpperCase(s.charAt(i))) {
count++;
}
}
System.out.println(count + 1);
}
}
/*==============================================================
Hackerank solution
import java.util.*;
public class Solution {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String s = scan.next();
scan.close();
// use a regex matching to split the string on capital letters
// the resulting array contains contiguous sections of lowercase letters
String[] words = s.split("[A-Z]");
// this works because the problem states that each word has at least 2 characters, and we know that the first character of each word is always capitalized.
System.out.println(words.length);
}
}
*/