Notice
Recent Posts
Link
Tags
- 스프링
- 프로그래머스
- Django
- static
- 1차원 배열
- sql
- 자바
- spring
- Docker
- AWS
- join
- DI
- mysql
- select
- spring security 6
- jpa
- 스프링부트
- springboot
- 데이터베이스
- 문자열
- spring mvc
- nginx
- spring boot
- PYTHON
- SSL
- ORM
- hibernate
- java
- @transactional
- string
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 31 |
Archives
개발하는 자몽
[4673] 함수 - 셀프 넘버 본문
문제

코드
public class Main {
public static void main(String[] args) {
boolean[] check = new boolean[10001]; // 1~10000
for (int i = 1; i <= 10000; i++) {
int n = d(i); //생성자가 있는 수, 즉 출력하면 안되는 수
if (n < 10001) { //10000이 넘는 수는 필요 없음
check[n] = true;
}
}
StringBuilder sb = new StringBuilder();
for(int i=1; i<= 10000; i++){
if(!check[i]) {
sb.append(i).append('\n');
}
}
System.out.println(sb);
}
public static int d(int n) {
int sum = n; //n은 생성자라고 하자
while (n != 0) {
sum += n % 10;
n /= 10;
}
return sum;
}
}'Algorithm' 카테고리의 다른 글
| [11654]문자열 - 아스키 코드 (0) | 2022.04.12 |
|---|---|
| [1065] 함수 - 한수 (0) | 2022.04.11 |
| [15596] 함수 - 정수 N개의 합 (0) | 2022.04.09 |
| [4344] 1차원 배열 - 평균은 넘겠지 (0) | 2022.04.01 |
| [8958] 1차원 배열 - OX퀴즈 (0) | 2022.03.31 |
Comments