Chapter Table of Contents
Ch. 3 DataSubsection Table of Contents
Chapter Table of ContentsSubsection Table of ContentsPracticeInitializeWithout EndFirst HalfString Slicer
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.)
There may be more than 1 correct answer.
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.
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.
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"
Previous Section
3.1 Primitive TypesNext Section
Chapter 3 QuizCopyright © 2021 Code 4 Tomorrow. All rights reserved.
The code in this course is licensed under the MIT License.
If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.