class ReplaceSpaces {

  public void replace(char[] input) {
    validateInput(input);

    char[] result = new char[input.length];
    for (int i = 0, j = 0; i < input.length && j < input.length; i++, j++) {
      if (input[i] == ' ') {
        result[j++] = '%';
        result[j++] = '2';
        result[j] = '0';
      } else {
        result[j] = input[i];
      }
    }
    copyArray(result, input);
  }

}