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();
	}
}

 

예제 1
예제 2

 

예제 3

 

+ Recent posts