Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags more
Archives
Today
Total
관리 메뉴

요리사에서 IT개발자로

핸드폰 번호 가리기(Java) 본문

Code Kata

핸드폰 번호 가리기(Java)

H.S-Backend 2024. 5. 18. 11:05

문제 설명

프로그래머스 모바일은 개인정보 보호를 위해 고지서를 보낼 때 고객들의 전화 번호의 일부를 가립니다.

전화번호가 문자열 phone_number로 주어졌을 때, 전화번호의 뒷 4자리를 제외한 나머지 숫자를 전부 *으로 가린 문자열을 리턴하는 함수,soulutuon을 완성해주세요.

 

제한조건

phone_number는 길이 4이상, 20이하인 문자열 입니다.

 

StringBuilder를 사용하여 char타입안의 배열을 Stringbuilder로 변환하여 출력하였으나.

다른 사람의 풀이를 보고 조금 더 직관적으로 변환시킴.

 

for문을 통해 인덱스를 생성하여 char[] array를 순회,

if문을 사용하여 array.length-4 를 input에 입력하며 접근

결국 변환 -> 다시 변환 이기에 직관적으로 변환.

 

  1. for문을 통해 char[]array안에 phone_number를 -4까지만 *로 변환시키고
  2. String.valueOf를 통하여 출력한다.

https://github.com/Hyungs0703/Algorithms_J.S

 

GitHub - Hyungs0703/Algorithms_J.S: This is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https:/

This is an auto push repository for Baekjoon Online Judge created with [BaekjoonHub](https://github.com/BaekjoonHub/BaekjoonHub). - Hyungs0703/Algorithms_J.S

github.com

 


다른사람의 정규식 풀이

반응형