Java betterprogrammer.com Пример заданий теста (первые 2 из 4-ёx)

задачи были такие (первые две):

  • 1) разбить строку на числа и подсчитать сумму
  • 2) подсчитать число полнократных числе в диапазоне от N до M

рекомендации:
If necessary, you may add auxiliary methods and static classes to this class. Please DO NOT change the given code including method signatures, class names, etc. Just add your implementation. Please import ONLY standard Java 1.5-1.6 classes. Your package statement will be ignored. You will get the maximum result if you solve the task correctly within the recommended time.

Задача 1:

public class BetterProgrammerTask {

    public static int getSumOfNumbers(String s) {
        /*
          Please implement this method to
          return the sum of all integers found in the parameter String. You can assume that
          integers are separated from other parts with one or more spaces (' ' symbol).
          For example, s="12 some text 3  7", result: 22 (12+3+7=22)
         */
    }
}

Задача 2

примечание о полнократном числе


public class BetterProgrammerTask {

    public static int countPowerfulNumbers(int from, int to) {
        /*
          A powerful number is a positive integer m that for every prime number p dividing m, p*p
also divides m.

          (a prime number (or a prime) is a natural number that has exactly two (distinct) natural number divisors,
          which are 1 and the prime number itself, the first prime numbers are: 2, 3, 5, 7, 11, 13, ...)

          The first powerful numbers are: 1, 4, 8, 9, 16, 25, 27, 32, 36, ...

          Please implement this method to
          return the count of powerful numbers in the range [from..to] inclusively.
         */
    }
}