From 8c35987ee0b82132ca403495171c8917e6e481a4 Mon Sep 17 00:00:00 2001 From: mehaksaini Date: Tue, 16 Jan 2024 14:43:53 -0800 Subject: [PATCH 1/3] file --- .idea/misc.xml | 1 - .idea/vcs.xml | 6 ++++++ src/Main.java | 27 ++++++++++++++++++--------- 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 .idea/vcs.xml 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..baa5fa6 100644 --- a/src/Main.java +++ b/src/Main.java @@ -38,7 +38,7 @@ with a buffer (similar to how a resizable ArrayList, and/or a public class Main { public static final int BUFFER_CAPACITY = 32768; - public static void main(String[] args) { + public static int main(String[] args) { //TIP Press with your caret at the highlighted text // to see how IntelliJ IDEA suggests fixing it. System.out.println("Hello and welcome!"); @@ -58,15 +58,24 @@ public static void main(String[] args) { System.out.println(Arrays.toString(buffer)); System.out.println("size: " + size); - // call your method here - - // check the "after" buffer contents via println - // check to see if the new buffer's size is correct - - + // write your method here + public static int a ( char[] buffer, int size)int numOfSpaces; + { + numOfSpaces = 0; + for (int i = 0; i < size; i++) { + if (buffer[i] == ' ') { + numOfSpaces++; + } + } + } + int newSize = size + (2 * numOfSpaces); + for (int i = size - 1; i >= 0; i-- );{ + shiftRight2(i); + } + return newSize; } - // write your method here - + public static void shiftRight2(char[] buffer, int startIndex) { + } } \ No newline at end of file From cbc688446352ca0eaa6cb3554580b27a2bc2e2b9 Mon Sep 17 00:00:00 2001 From: mehaksaini Date: Fri, 26 Jan 2024 17:50:10 -0800 Subject: [PATCH 2/3] git commit -m "add file" --- src/InterviewQuestion1-3/Main.class | Bin 0 -> 1563 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 src/InterviewQuestion1-3/Main.class diff --git a/src/InterviewQuestion1-3/Main.class b/src/InterviewQuestion1-3/Main.class new file mode 100644 index 0000000000000000000000000000000000000000..f7ff0a8ae01e86f74702642f7c4156f023c8957d GIT binary patch literal 1563 zcmaKsUsGE}7{;GXLQWEcslk*Yh(T#hiY01mt%Ov=X_3%Cv4M0PE_4Z7a>~g$nUhT& zyz-(S!t366U#by!-BrT-Ucm?TG^2Sk5s}5Cu zpFz2Ln8@)c$2%w&n-$Hh589lqoJJ9XWbIr)-(saG}+fL6rt$g<8>0;UX?scsGp#iZ2rNwd0nm zK_HKM0txL800qt$cJ1OQc$Vj|kj8tsA~4yJhsyT7melth-Da<+rKg!E$8w{w0-2Sa z)z#bgzOt)ZRlBzRrGTgjjK7F%O1G~FYy10bGIhsOoBht73by5*%b9H5Z%MZ)1ILVq zlQG?PSTbHWds$|5hi%9|N>FUFqC<@g4j41BJ1SwOz5as-DiDb5+LZR3Zw(V~OV<#* zym7;$B!5H8*5QWihC~*YEG#p+Pl`Bqu~wwV_{uP8s^Ry8mRfa;p`>A6G%0x;E55IL zI*{EBrQ7~~FM)MlBU64UFEVk|Q`o?!g}Y|^w*=;2qB!0o|4@|%M1vDql`ZWDM*`oU zynaLBpu!q2wX1sbb>Bbicgv&JPRyJN+&=26Gvp_CbMSL4pS%Ub6t;BThNBgaDqZtD z71*xq^;FM7L*U|wr?XHk> Date: Fri, 8 Mar 2024 18:38:02 -0800 Subject: [PATCH 3/3] updated InterviewQuestions1-3 --- src/Main.java | 55 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/src/Main.java b/src/Main.java index baa5fa6..7140999 100644 --- a/src/Main.java +++ b/src/Main.java @@ -38,7 +38,7 @@ with a buffer (similar to how a resizable ArrayList, and/or a public class Main { public static final int BUFFER_CAPACITY = 32768; - public static int main(String[] args) { + public static void main(String[] args) { //TIP Press with your caret at the highlighted text // to see how IntelliJ IDEA suggests fixing it. System.out.println("Hello and welcome!"); @@ -54,28 +54,57 @@ public static int 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); - // write your method here - public static int a ( char[] buffer, int size)int numOfSpaces; - { - numOfSpaces = 0; - for (int i = 0; i < size; i++) { - if (buffer[i] == ' ') { - numOfSpaces++; - } + // 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-- );{ - shiftRight2(i); + //new size replaced with %20 + int newSize =size+(2*numOfSpace); + + for(int i = size-1; 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; } - public static void shiftRight2(char[] buffer, int startIndex) { + //print buffer and size + public static void shiftRight2(char[]buffer, int size){ + StringBuilder output = new StringBuilder(); + for(int i =0; i