-
Notifications
You must be signed in to change notification settings - Fork 0
/
theeasiestproblemisthisone.java
47 lines (36 loc) · 1.31 KB
/
theeasiestproblemisthisone.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int intVal = Integer.parseInt(scanner.nextLine());
List<Integer> numberList = new ArrayList<>();
while (intVal != 0) {
numberList.add(intVal);
intVal = Integer.parseInt(scanner.nextLine());
}
for (int number : numberList) {
boolean foundAnswer = false;
int numSum = 0;
int counter = 11;
String[] numSplit = Integer.toString(number).split("");
for (String splitVal : numSplit) {
numSum += Integer.parseInt(splitVal);
}
while (!foundAnswer) {
int total = number * counter;
int totalSplit = 0;
String[] split = Integer.toString(total).split("");
for (String splitVal : split) {
totalSplit += Integer.parseInt(splitVal);
}
if (totalSplit == numSum) {
System.out.println(counter);
foundAnswer = true;
}
counter += 1;
}
}
}
}