package Hansu;
import java.util.Scanner;
class hansu {
public int x;
hansu() {
this.x = 0;
}
public boolean sumDigit(int temp) {
int i = 0, j = 0, k = 0;
i = temp / 100;
j = (temp - i * 100) / 10;
k = temp % 10;
return (i - j) == (j - k);
}
public int searchHansu(int temp) {
int sum = 0;
if (temp > 1000||temp<1) {
System.out.println("숫자 범위 오류");
} else if (temp >= 100) {
for (int a = 100; a <= temp; a++) {
if (sumDigit(a)) {
sum++;
}
}
sum += 99;
} else
sum = temp;
return sum;
}
}
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
hansu test = new hansu();
System.out.print("Input Num : ");
int temp = scan.nextInt();
System.out.println(test.searchHansu(temp));
scan.close();
}
}
'알고리즘' 카테고리의 다른 글
[BAEKJOON 10809번] (Java) 알파벳 찾기 (0) | 2020.06.18 |
---|---|
[BAEKJOON 2292번] (Java) 벌집 (0) | 2020.06.18 |
[BAEKJOON 2941번] (Java) 크로아티아 알파벳 (0) | 2020.06.15 |
[BAEKJOON 10250번] (Java) ACM호텔 (0) | 2020.06.15 |
[BAEKJOON 2798번] (Java) 블랙잭 (0) | 2020.06.15 |