diff --git a/.idea/misc.xml b/.idea/misc.xml index 6f29fee..5af9c98 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,3 @@ - diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/Main.java b/src/Main.java index 0282a9d..c7f9bb2 100644 --- a/src/Main.java +++ b/src/Main.java @@ -59,14 +59,48 @@ public static void main(String[] args) { System.out.println("size: " + size); // call your method here + size = replaceSpaces(buffer, size); // check the "after" buffer contents via println // check to see if the new buffer's size is correct - + System.out.println(Arrays.toString(buffer)); + System.out.println("size: " + size); } // write your method here + public static int replaceSpaces(char[] buffer, int size) { + // loops through buffer array + for(int i = 0; i < size; i++) { + // checks if char is equal to whitespace + if(buffer[i] == ' ') { + + // loops from end of the array up until the whitespace + shiftRight(buffer, i, size); + + // adds all the new characters + buffer[i] = '%'; + buffer[i + 1] = '2'; + buffer[i + 2] = '0'; + + // increases size + size += 2; + } + } + return size; + } + + public static void shiftRight(char[] buffer, int start, int size) { + for(int i = size + 2; i > start; i--) { + // in case the space is at the index 0 or 1 + if(start <= 1 && i == (start + 1)) { + buffer[i] = '*'; + } else { + buffer[i] = buffer[i - 2]; + } + + } + } } \ No newline at end of file