문제 15596) 정수 N개의 합
public class Test {
long sum(int[] a) {
long ans = 0;
for(int i=0;i<a.length;i++) {
ans+=a[i];
}
return ans;
}
}
문제 4673) 셀프 넘버
public class Main {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
boolean self[] = new boolean[10001];
for(int i=1;i<10000;i++) {
d(self,i);
}
for(int i=1;i<self.length;i++) {
if(!self[i]) {
sb.append(i).append("\n");
}
}
System.out.print(sb);
}
static void d(boolean self[], int i) {
int temp = i;
while(temp>0) {
i+=temp%10;
if(i>10000)
return;
temp/=10;
}
self[i]=true;
}
}
문제 1065) 한수
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class b_1065 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
System.out.println(hansu(N));
}
private static int hansu(int N) {
int count = 0;
for(int i=1;i<=N;i++) {
if(i<100) {
count++;
}
else if(i<1000) {
int h = i/100;
int t = i/10%10;
int k = i%10;
if(h-t==t-k) {
count++;
}
}
}
return count;
}
}
'백준 > JAVA' 카테고리의 다른 글
[백준/JAVA] 2941번 크로아티아 알파벳 (0) | 2023.01.18 |
---|---|
[백준/JAVA] 2908번 상수 (0) | 2023.01.18 |
[백준/JAVA] 단계별로 풀어보기(4단계) 코드 모음 (0) | 2023.01.18 |
[백준/JAVA] 8958번 OX퀴즈 (0) | 2023.01.18 |
[백준/JAVA] 2577번 숫자의 개수 (0) | 2023.01.18 |