I was wondering what I'm doing wrong, I tried to split the digits of an int and enter them into an array in Java. I don't know whats wrong, am I missing something when dealing with the array?
The array is declared like so:
int[] digits = new int [100];
Here is the logic:
while (r > 0) {
// puts digits of n into array
count = 0;
sum = 0;
while (n != 0) {
digits[count] = n % 10;
count++;
n = n / 10;
}
// squares digits[] and populates into sum
for (i = 0; i < count; i++) {
sum = sum + digits[i]*digits[i];
}
// if sum is 1 then print 'Number is a happy number'
if (sum == 1) {
addItems(b);
r = 0;
} else {
r--;
}
}
Any help would be very much appreciated as I've been looking through the web for a few days now and haven't found any real help
System.out.println("Number is a happy number");inif(sum == 1)and it's not working or what?