백준 알고리즘/JAVA
백준 4673번 셀프 넘버
RECORD :D
2019. 1. 21. 16:13
셀프 넘버
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 | import java.util.ArrayList; import java.util.Collections; public class Main { public static void main(String[] args){ ArrayList<Integer> list = new ArrayList<Integer>(); for(int i=0; i<=10000; i++) { list.add(self_num(i)); } Collections.sort(list); for(int i=0; i<=10000; i++) { if(!(list.contains(i))) { System.out.println(i); } } } static int self_num(int num) { int sum=0; String st_num = String.valueOf(num); sum+=num; for(int i=0; i<st_num.length(); i++) { sum+=Integer.parseInt(String.valueOf(st_num.charAt(i))); } return sum; } } | cs |