Tell me, how in a similar method to avoid duplication of code?
public static int[] findNumbers(int n) { int[] result = new int[(int) Math.sqrt(n)]; for (int i = 1; i * i < n; i++) { result[i - 1] = i * i; } return result; } Tell me, how in a similar method to avoid duplication of code?
public static int[] findNumbers(int n) { int[] result = new int[(int) Math.sqrt(n)]; for (int i = 1; i * i < n; i++) { result[i - 1] = i * i; } return result; } Source: https://ru.stackoverflow.com/questions/602522/
All Articles
int j = 0; for (int i = 1; (j = i * i) < n; i++) { result[i - 1] = j; }int j = 0; for (int i = 1; (j = i * i) < n; i++) { result[i - 1] = j; }heh ..... - Alexey Shimansky