-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasiest.java
48 lines (40 loc) · 1004 Bytes
/
easiest.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
package programming_challenges;
import java.util.Scanner;
public class easiest{
public static void main(String [] args){
Scanner input = new Scanner(System.in);
//gets the input number to test
while(input.hasNextLine()){
int N = Integer.parseInt(input.nextLine());
//if its 0, exit loop
if(N == 0) break;
//call get sum to test
getSum(N);
}
//close the scanner
input.close();
}
//checks the sum of digits in N against the sum of digits of p*N
public static void getSum(int N){
int p = 11; //we use values greater than 10
boolean found = false;
//loops until the lowest number that satisfies the condition is found
while(!found){
int mult = p*N;
if(sumDigits(mult) == sumDigits(N)){
System.out.println(p);
found = true;
}
else p++;
}
}
//simply sums up the digits of a given number
public static int sumDigits(int in){
int sum = 0;
while(in > 0){
sum = sum +(in%10);
in = in/10;
}
return sum;
}
}