Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed the counter method. Need to update the name of the method as it… #8

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/LinkedList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

33 changes: 28 additions & 5 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,39 @@ public static void main(String[] args) {
// check the "before" buffer and size via println
System.out.println(Arrays.toString(buffer));
System.out.println("size: " + size);

// call your method here

counter(buffer, size);
// check the "after" buffer contents via println
System.out.println(Arrays.toString(buffer));
// check to see if the new buffer's size is correct

System.out.println("size: " + size);

}

// write your method here

public static void counter(char[] buffer, int size) { //changed from int to void to avoid return statement
int spaceNumbers = 0;
for (int j = 0; j < size; j++) {
if (buffer[j] == ' ') {
spaceNumbers++;
// Start by counting the spaces in the array
} //fixed an issue where using an int as a variable required a return statement.
// it creates confusion and is easiest set as void
}

int newArray = size + (spaceNumbers * 2); //double each space to create space for the %20
//This for loop goes through each white space and inserts a % then 2 then 0.
// note the array SIZE doubles so that the new buffer has enough space
//This is different that the length of the array in which there seams to be plenty of room.
for (int i = size - 1; i >= 0; i--) {
if (buffer[i] == ' ') {
buffer[newArray - 1] = '0';
buffer[newArray - 2] = '2';
buffer[newArray - 3] = '%';
newArray = newArray - 3;
} else {
buffer[newArray - 1] = buffer[i]; //copy the original buffer to the new array
newArray--;
}
}
}
}