15596번 정수 N개의 합
문제

풀이
public class Test {
long sum(int[] a) {
long answer = 0;
for(int i = 0; i < a.length; i++) {
answer += a[i];
}
return answer;
}
}
4673번 셀프 넘버
문제

풀이
public class Main {
static boolean[] arr = new boolean[20002];
public static void d(int n) {
int tmp = n;
int sum=0;
sum = tmp;
if(tmp <= 10000 && !arr[tmp]) {
while(tmp > 0) {
sum += tmp % 10;
tmp /= 10;
}
d(sum);
arr[sum] = true;
}
}
public static void main(String[] args) {
for(int i = 1; i <= 10000; i++) {
d(i);
}
for(int i = 1; i <= 10000; i++) {
if(!arr[i]) {
System.out.println(i);
}
}
}
}
1065번 한수
문제

풀이
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int cnt = 0;
int a = 0;
int b = 0;
int c = 0;
for(int i = 1; i <= n; i++) {
if(i / 100 >= 1) {
a = i / 100;
b = (i % 100) / 10;
c = (i % 100) % 10;
if((b - a) == (c - b)) {
cnt++;
}
} else {
cnt++;
}
}
System.out.println(cnt);
sc.close();
}
}