COMP2396
Loading...
Searching...
No Matches
Question2.java
Go to the documentation of this file.
1import java.io.*;
2
3public class Question2 {
4 public static int digit_sum(int n) {
5 int sum = 0;
6 while (n > 0) {
7 sum += n % 10;
8 n /= 10;
9 }
10 return sum;
11 }
12 public static int d(int n) {
13 return n + digit_sum(n);
14 }
15 public static boolean is_self_number(int n) {
16 for (int i = 1; i < n; i++) {
17 if (d(i) == n) {
18 return false;
19 }
20 }
21 return true;
22 }
23 public static void main(String[] args) throws IOException {
24 InputStreamReader reader = new InputStreamReader(System.in);
25 BufferedReader buffer = new BufferedReader(reader);
26 int n = Integer.parseInt(buffer.readLine());
27 for (int i = 1; i < n; i++) {
28 if (is_self_number(i)) {
29 System.out.println(i);
30 }
31 }
32 }
33}
static void main(String[] args)
static int digit_sum(int n)
Definition Question2.java:4
static boolean is_self_number(int n)
static int d(int n)