https://programmers.co.kr/learn/courses/30/lessons/82612
public class Solution {
public String solution(String new_id) {
// 1단계
String id = new_id.toLowerCase();
// 2단계
String answer = "";
for (int i=0; i<id.length(); i++) {
if ((id.charAt(i) >= 'a' && id.charAt(i) <= 'z') || (id.charAt(i) >= '0' && id.charAt(i) <= '9') || id.charAt(i) == '-' || id.charAt(i) == '_' || id.charAt(i) == '.') {
answer += id.charAt(i);
}
}
// 3단계
while (answer.contains("..")) {
answer = answer.replace("..", "."); // answer = 을 붙여줘야 먹힘
}
// 4단계
if (answer.length() > 0) {
if (answer.charAt(0) == '.') {
answer = answer.substring(1);
}
}
if (answer.length() > 0) {
int len = answer.length();
if (answer.charAt(len-1) == '.') {
answer = answer.substring(0, len-1);
}
}
// 5단계
if (answer.equals("")) { // 문자열 일치여부는 .equals()
answer += "a";
}
// 6단계
if (answer.length() >= 16) {
answer = answer.substring(0, 15);
if (answer.charAt(answer.length()-1) == '.') {
answer = answer.substring(0, answer.length()-1);
}
}
// 7단계
if (answer.length() <= 2) {
char add_word = answer.charAt(answer.length()-1);
System.out.println(add_word);
while (answer.length() < 3) {
answer += add_word;
}
}
return answer;
}
}