Hey,
I've been doing this little program to check if a number is a Keith number, and for some reason it's not working. I've gone over the code a few times but still can't detect the error. Could you please help?

``````static boolean isKeith(int n)
{
int sz=Func.sumDg(n);
int arr[]=new int[sz];
int i=0,k=n;
while(n>0)
{
arr[i]=n%10;
i++;
n/=10;
}
Disp.shw1D(arr);
int sum=Func.sumArr(arr);

while(sum<k)
{
for(int j=0;j<sz-1;j++)
{
arr[j]=arr[j+1];
}
arr[sz-1]=sum;
if(sum==k) return true;
sum=Func.sumArr(arr);
}
return false;
}``````

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span

Can you explain what is a Keith number?

Can you explain what is a Keith number?

it means a number whose digits and consecutive sums add up to the same number. such as 197

you have 1+9+7=17, then 9+7+17=33, then 7+17+37.....and so on till you get 197 and so its a Keith number...

it means a number whose digits and consecutive sums add up to the same number. such as 197

you have 1+9+7=17, then 9+7+17=33, then 7+17+37.....and so on till you get 197 and so its a Keith number...

Ok.