Algorithm/[프로그래머스] Java
[프로그래머스] Lv. 1 | 핸드폰 번호 가리기
구구르밍
2023. 11. 21. 10:24
핸드폰 번호 가리기
문제 설명
프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화번호의 일부를 가립니다.
전화번호가 문자열 phone_number로 주어졌을 때,
전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수, solution을 완성해주세요.
제한사항
- phone_number는 길이 4 이상, 20이하인 문자열입니다.
입출력 예
phone_number | return |
"01033334444" | "*****4444" |
"027778888" | "*****8888" |
코드
class Solution {
public String solution(String phone_number) {
String answer = "";
return answer;
}
}
풀이
class Solution {
public String solution(String phone_number) {
String answer = "";
// 핸드폰 번호 수 - 4
for (int i = 0; i < phone_number.length() - 4; i++)
answer += "*";
answer += phone_number.substring(phone_number.length() - 4);
return answer;
}
}
https://school.programmers.co.kr/learn/courses/30/lessons/12948
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr