Im currently trying to create a Algorithm who is supposed to be able to line up numbers with a specific digit sum. For example numbers with a digit sum of 13 in between 1 and 500. Could someone give me some advice on how to proceed please?
My current progress:
public class Digitsum{
static int Digitsum2(int number) { //method to find out the digit sum from numbers between 1 and 500
int sum = 0;
if(number == 0){
return sum;
} else {
sum += (number%10);
Digitsum2(number/10);
}
return sum;
}
static int Digitsum13(int x) { //method to line up the numbers with a digit sum of 13
while (x <= 500) {
x++;
Digitsum2(x);
}
return x;
}
public static void main(String[ ] args) {
Digitsum13(13);
}
}