Skip to content

Instantly share code, notes, and snippets.

@udhaya21
Created November 4, 2020 10:50
Show Gist options
  • Save udhaya21/9c13c4f0a51219ed958f693a36d77d98 to your computer and use it in GitHub Desktop.
Save udhaya21/9c13c4f0a51219ed958f693a36d77d98 to your computer and use it in GitHub Desktop.
This time no story, no theory
// Accumul.accum("abcd"); // "A-Bb-Ccc-Dddd"
// Accumul.accum("RqaEzty"); // "R-Qq-Aaa-Eeee-Zzzzz-Tttttt-Yyyyyyy"
// Accumul.accum("cwAt"); // "C-Ww-Aaa-Tttt"
public class Accumul {
public String accum(String s) {
StringBuilder result = new StringBuilder();
int i = 0;
for (char c : s.toCharArray()) {
if (i > 0)
result.append('-');
result.append(Character.toUpperCase(c));
for (int j = 0; j < i; j++)
result.append(Character.toLowerCase(c));
i++;
}
return result.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment