Click to reopen instructions.

This is a sample of methods that compute using Strings (and a few booleans and numbers) with the methods covered in Chapter 7 and the String + operator. As is usually the case when writing methods, you should be on the lookout for opportunities to implement methods in terms of other methods you’ve already written, especially in the later problems.

Quick reference

  • String s = "Foo";
  • s + s ⟹ "FooFoo"
  • s.substring(0, 1) ⟹ "F"
  • s.length() ⟹ 3
  • s.toUpperCase() ⟹ "FOO"
  • s.toLowerCase() ⟹ "foo"
  • s.indexOf("o") ⟹ 1

Pro tip: when you click one of the method buttons, the name of the method is copied to your clipboard so you can paste it into your code, saving typing and avoiding spelling errors. Finally, click the black triangle at the start of these instructions to collapse them and have more room to code.

Put definitions here.

Revisions:

Errors