id/email
password
forgot password | create account
about | help | code help+videos | done | prefs
CodingBat code practice

orion.a.smith@gmail.com hcs-strings

Description:Honors Computer Science - String problems

Remember the structure of a CodingBat solution in my class, to keep you from skipping important information:


Step 1: create an output variable and assign it an initial value.  This should be of the same data type as the method you are filling out, so if the method signature is public boolean areMyEyesClosed, the data type is boolean and you should create an output variable like
boolean output = false;
You can name your output variable whatever you like.

Step 3: go to the bottom of the method and return your output variable. This is totally simple, make the last line of your method read as

return output;
(assuming that your variable is called output) Yes, I'm asking you to do step 3 second, but it goes at the bottom so that makes sense.

Step 2: read the actual problem description and use logic to assign a new value to your output variable. This is likely going to include some combination of if statements and loops, and some problems are clearly more complex than others. This code should go in between the first statement (declaring an output variable) and the last statement (returning your output variable).

This is not the most efficient way to solve a problem, but it keeps you thinking about the important idea that each CodingBat problem is working its way toward returning an output variable of a certain data type. When you get to AP Computer Science A, remembering this method structure may save your behind on a handwritten free response question.


This page of String problems is to supplement the ones provided by CodingBat.  See the excellent String-1, String-2 and String-3 stock problems for those.

Very useful introduction! Once you get to a problem in this series, scroll to the bottom of the page and you will see several links to great tutorials about Strings right here on the CodingBat site.

Use your reference.  The first several problems include hints which point you to pages in your string reference packet.  The packet exists for a reason and you should use it to learn.

String problems, no loops

These problems will just test your basic knowledge of String methods: equals, length, indexOf and substring.  Remember that indexOf and substring each have versions with one and two parameters, which modify the way they work!

apcsaStringsReturnString  apcsaStringsReturnLength H   apcsaStringsSameLength H   apcsaStringsAreEqual H   apcsaStringsFirstOccurrence H   apcsaStringsOccurrenceAfter  apcsaStringsGimmeFirstFive H   apcsaStringsGimmeMaybeFirstFive  apcsaStringsBabyTalk  apcsaStringsGimmeFifth  apcsaStringsGimmeFifth2  apcsaStringsGimmeSingle  apcsaStringsGimmeLastFive  apcsaStringsGimmeLastN  apcsaStringsGimmeDoubled  apcsaStringsFirstWordOccursLater  apcsaStringsFirstFiveEqual  apcsaStringsFirstFiveSearch  apcsaStringsGimmeLastThreeReversed 

String problems, with loops


These problems add in the idea of looping over the characters in a String, which is necessary to solve many more advanced challenges.  You will need to combine loops with substrings using index positions to do well on these problems.

apcsaStringsGimmeEvens  apcsaStringsGimmeOdds  apcsaStringsGimmeNs 


Authoring docs

Copyright Nick Parlante 2017 - privacy