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 32 33 34 35 36 37 38 39 40 41 42 43 | import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; public class SelfNumber { public static void main(String[] args) { // 20210623 - 4673번 //10000보다 같거나 작은 셀프 넘버 한 줄에 하나씩 출력 //////////////////////////////////////////////////////////////////////////이해 못함 boolean[] check = new boolean[10001]; for (int i = 1; i < 10001; i++) { int n = d(i); if (n < 10001) { check[n] = true; } } StringBuilder sb = new StringBuilder(); for (int i = 1; i < 10001; i++) { if (!check[i]) { sb.append(i + "\n"); } } System.out.println(sb); } public static int d(int number) { int sum = number; while (number != 0) { sum += (number % 10); number /= 10; } return sum; } } | cs |
'코딩테스트 > 백준' 카테고리의 다른 글
Java - 백준 코딩테스트 4344번 [1차원 배열 - 평균은 넘겠지] (0) | 2021.06.24 |
---|---|
Java - 백준 코딩테스트 15596번 [함수 - 정수 N개의 합] (0) | 2021.06.24 |
Java - 백준 코딩테스트 11720번 [문자열 - 숫자의 합] (0) | 2021.06.24 |
Java - 백준 코딩테스트 11654번 [문자열 - 아스키 코드] (0) | 2021.06.24 |
Java - 백준 코딩테스트 1065번 [함수 - 한수] (0) | 2021.06.24 |