Chapter Table of Contents

Ch. 3 Data

Subsection Table of Contents

Practice

Initialize

Let's practice initializing different primitive types. In the code below (see downloads), there are variables initialized, but they don't have a type! Based on the name of the variable and its value, write the correct type in front of the variable's name so that the program works. (Be sure to uncomment everything when you begin working.)

<aside> 💡 There may be more than 1 correct answer.

</aside>

💻 Template Code

✅ Solution Code

Without End

Given 3 strings that are at least 2 characters long, print each string without its first and last character. Hint: Use the length() method on a string to get the number of characters that make up that string.

💻 Template Code

✅ Solution Code

First Half

Given 3 strings of even length, print the first half of each string. Hint: Use the length() method on a string to get the number of characters that make up that string.

Adapted from firstHalf (CodingBat)

💻 Template Code

✅ Solution Code

String Slicer

Use String Methods to convert the following strings to the results:a) "A Tale of Two Cities" -> "WO CIT"b) "A Handmaid's Tale" -> "s"c) "wE LoVe tO CoDe" -> "e love to code"

💻 Template Code

✅ Solution Code

Previous Section

3.1 Primitive Types

Next Section

Chapter 3 Quiz