mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-05-15 17:58:44 +00:00
[Sync Iteration] java/squeaky-clean/1
This commit is contained in:
parent
f80fbca12e
commit
fe09c7d626
@ -0,0 +1,28 @@
|
||||
class SqueakyClean {
|
||||
static String clean(String identifier) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
boolean toUpper = false;
|
||||
String replace = identifier.replace(" ", "_")
|
||||
.replace("4", "a")
|
||||
.replace("3", "e")
|
||||
.replace("0", "o")
|
||||
.replace("1", "l")
|
||||
.replace("7", "t");
|
||||
for (char c : replace.toCharArray()){
|
||||
if (!Character.isLetter(c) && c != '_' && c != '-') {
|
||||
continue;
|
||||
}
|
||||
if (c == '-') {
|
||||
toUpper = true;
|
||||
} else {
|
||||
if (toUpper) {
|
||||
result.append(Character.toUpperCase(c));
|
||||
toUpper = false;
|
||||
} else {
|
||||
result.append(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user