Skip to content

Instantly share code, notes, and snippets.

@M-ZubairAhmed
Created March 17, 2017 05:23
Show Gist options
  • Save M-ZubairAhmed/629c4679680bff1693678c99d22f2f30 to your computer and use it in GitHub Desktop.
Save M-ZubairAhmed/629c4679680bff1693678c99d22f2f30 to your computer and use it in GitHub Desktop.
Pattern generating algorithm. eg: abcd -> A-Bb-Ccc-Dddd
public class Accumul {
public static String accum(String s){
StringBuilder stBuild = new StringBuilder();
for(int i = 0; i < s.length(); i++){
for(int j = 0; j <= i; j++) {
if (j==0){
stBuild.append(s.toUpperCase().charAt(i));
}
else {
stBuild.append(s.toLowerCase().charAt(i));
}
}
stBuild.append('-');
}
stBuild.delete(stBuild.length()-1,stBuild.length());
return stBuild.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment