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/InterviewQuestion1-3/Main.class b/src/InterviewQuestion1-3/Main.class new file mode 100644 index 0000000..f7ff0a8 Binary files /dev/null and b/src/InterviewQuestion1-3/Main.class differ diff --git a/src/Main.java b/src/Main.java index 0282a9d..7140999 100644 --- a/src/Main.java +++ b/src/Main.java @@ -54,19 +54,57 @@ public static void main(String[] args) { } size = temp.length(); + // check the "before" buffer and size via println System.out.println(Arrays.toString(buffer)); System.out.println("size: " + size); // call your method here - + System.out.println("before:"); + shiftRight2(buffer, size); + int newSize = replaceSpace(buffer, size); // check the "after" buffer contents via println // check to see if the new buffer's size is correct - + System.out.println("after:"); + shiftRight2(buffer, newSize); } // write your method here + public static int replaceSpace(char[]buffer, int size){ + int numOfSpace =0; + //count number of space + for(int i =0; i=0; i--){ + if (buffer[i]==' '){ + buffer[i+2*numOfSpace]='0'; + buffer[i+2*numOfSpace-1]='2'; + buffer[i+2*numOfSpace-2]='%'; + numOfSpace--; + }else{ + buffer[i+2*numOfSpace]=buffer[i]; + } + } + return newSize; + } + + //print buffer and size + public static void shiftRight2(char[]buffer, int size){ + StringBuilder output = new StringBuilder(); + for(int i =0; i