From 4ba997c46c655be4d771eac46adefb8186978ae6 Mon Sep 17 00:00:00 2001 From: Rob Smith Date: Thu, 11 Jan 2024 13:27:20 -0800 Subject: [PATCH 1/2] Built the solution --- src/Main.java | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Main.java b/src/Main.java index 0282a9d..899bda3 100644 --- a/src/Main.java +++ b/src/Main.java @@ -32,7 +32,6 @@ with a buffer (similar to how a resizable ArrayList, and/or a CareerCup, Palo Alto, CA. */ - import java.util.Arrays; public class Main { @@ -48,7 +47,7 @@ public static void main(String[] args) { int size = 0; // initialize the buffer and size variables with some data - String temp = "Dr Martin Luther King"; + String temp = "Do a jig"; for (int i = 0; i < temp.length(); i++) { buffer[i] = temp.charAt(i); } @@ -59,14 +58,26 @@ 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){ + for(int i = 0; i < size; i++){ + if(buffer[i]==' '){ + for(int j=size+3; j>=i ;j--){ + buffer[j+2] = buffer[j]; + } + buffer[i]='%'; + buffer[i+1] = '2'; + buffer[i+2] = '0'; + size=size+2; + } + } + return size; + } } \ No newline at end of file From 1ad2f48fd84c8ba070b5f2767cbb01bdb67815d2 Mon Sep 17 00:00:00 2001 From: Rob Smith Date: Thu, 11 Jan 2024 13:33:48 -0800 Subject: [PATCH 2/2] Adjusted test string. --- src/Main.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Main.java b/src/Main.java index 899bda3..3fd2e6c 100644 --- a/src/Main.java +++ b/src/Main.java @@ -47,7 +47,7 @@ public static void main(String[] args) { int size = 0; // initialize the buffer and size variables with some data - String temp = "Do a jig"; + String temp = "This starts as 38 and ends up with 54."; for (int i = 0; i < temp.length(); i++) { buffer[i] = temp.charAt(i); }