I have written a code that would return either 1 or 4 as the output, and here it is
public static int findSum(int k) {
int sum = 0;
boolean foundNonZero = false;
for (; k != 0; k /= 10) {
if (foundNonZero) {
sum += (k % 10)*(k % 10);
} else {
foundNonZero = k % 10 != 0;
}
}
return sum;
}
Now, I'm trying to write a function public static long[] firstK(int k) that would return k numbers starting from 0 that would satisfy the condition that findsum = 1.
I'm struggling to understand how to do it, despite reading Java syntax and information. and here is my code so far:
public static long[] firstK(int k) {
while (int x = 0;) {
if (findSum(x) = 1;)
System.out.println(x);
}
I know that int(k) isn't used in this, but I have no idea how to implement it. Any help would be greatly appreciated :)
Thank you, Dave Shah, MUIC