seventhmoon
BAN USERCan we use RegEx?
public static void main(String[] args){
String[] camelCaseWords = { "HelloMars", "HelloWorld", "HelloWorldMars", "HiHo" };
String input = "HeW"; //'This is an Example';
StringBuilder sb = new StringBuilder();
sb.append(input.charAt(0));
for (int i=1; i< input.length(); i++){
char curr = input.charAt(i);
if (curr >= 'A' && curr <= 'Z'){ //capital letter
sb.append("[a-z]*" + curr);
}else{
sb.append(curr);
}
}
sb.append("[a-z]*");
for (String s : camelCaseWords){
if (s.matches(sb.toString())){
System.out.println(s);
}
}
}
public static void main (String[] args){
int[] counter = new int[52];
String input = "AAbbbccccddeegg";
char[] inputArray = input.toCharArray();
for (char c : inputArray){
int index = ((int) c) - ((int) 'A');
counter[index]++;
}
for (int i =0; i< counter.length; i++){
if (counter[i] > 0){
System.out.print("(" + ((char) ('A' + i)) + "," + counter[i] + ") ");
}
System.out.flush();
}
}
private static final String[] availableChars = {"A", "B", "C"};
public static void main(String[] args){
TreeSet<String> combinations = getCombinations(5);
TreeSet<String> filteredCombinations = filter(combinations);
System.out.println(filteredCombinations);
}
private static TreeSet<String> filter(TreeSet<String> input){
TreeSet<String> output = new TreeSet<>();
for (String s : input){
if (!s.contains("CCC")){
if (s.indexOf('B') == s.lastIndexOf('B')) {
output.add(s);
}
}
}
return output;
}
private static TreeSet<String> getCombinations(int length){
TreeSet<String> output = new TreeSet<>();
if (length <= 1){
for (String character : availableChars) {
output.add(character);
}
}else {
TreeSet<String> set = getCombinations(length - 1);
for (String s : set) {
for (String character : availableChars) {
output.add(character + s);
}
}
}
return output;
}
- seventhmoon August 18, 2016