Could someone please explain to me what is wrong with the returned ARRAY?
package com.codegym.task.task20.task2025;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
/*
Number algorithms
*/
public class Solution {
public static long[] getNumbers(long N) {
long[] result = null;
long s= N-1;
int i=0;
ArrayList<Long> list = new ArrayList<>();
//put number that satisfy conditions in the list //
while ((0 <= s)) {
long u = s;
long somme = 0;
int n =String.valueOf(s).length();
while (s % 10 != 0) {
somme += Math.pow(s % 10, n);
s = s / 10;
}
if (u == somme) {
list.add(u);
}
//put elements in ascending order !!!
Collections.reverse(list);
result= new long[list.size()];
for (Long l : list) {
result[i++] = l;
}
s--;
}
return result;
}
public static void main(String[] args) {
long a = System.currentTimeMillis();
System.out.println(Arrays.toString(getNumbers(1000)));
long b = System.currentTimeMillis();
System.out.println("memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (8 * 1024));
System.out.println("time = " + (b - a) / 1000);
a = System.currentTimeMillis();
System.out.println(Arrays.toString(getNumbers(1000000)));
b = System.currentTimeMillis();
System.out.println("memory " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / (8 * 1024));
System.out.println("time = " + (b - a) / 1000);
}
}