// identify if the word is correctly camelcased when a set containing list of words is given. //isMyWordCamelCased - True //ismyWordCamelCased - False
// ("isMyWordCamelCased", ["cased", "my", "is", "word", "camel", ])
Here is my answer but I need help for last word "Cased" my loop finishing at "Case"
public class Exercise {
public static void main(String[] args) {
String str = "isMyWordCamelCased";
int counter = 0;
String[] arr = {"cased", "my", "is", "word", "camel"};
ArrayList<String> arrayList = new ArrayList<>(Arrays.asList(arr));
ArrayList<String> arrayList2 = new ArrayList<String>();
for (String s : arrayList) {
if (str.startsWith(s)) {
arrayList2.add(0, s);
} else {
String temp1 = s.substring(0, 1).toUpperCase() s.substring(1).toLowerCase();
arrayList2.add(0, temp1);
}
}
for (int i = 0; i < str.length() - 1; i ) {
for (int j = i 1; j <= str.length(); j ) {
String temp = (str.substring(i, j));
if (arrayList2.contains(str.substring(i,j))){
counter ;
}
}
}
if (counter == arr.length) {
System.out.println("word is camel case");
} else {
System.out.println("word is NOT camel case");
}
}
}
CodePudding user response:
