Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 21 Strings By using Bluej Using the given project Strings , complete each section in the class YourCode by using the methods specified in

Exercise 21 Strings By using Bluej

Using the given project Strings, complete each section in the class YourCode by using the methods specified in each exercise (you may declare additional variables). No need to ask the user to enter values; use the variables that are already declared in the method.

The class Testing already has testing cases to test your code. You simply need to compile and execute either the main method or each section of this class.

Details about methods of the class String can be found in the String lecture slides. The method length() requires no parameters and it returns the length of the string as an int.

Folder name: A170_E21_YourLastName_YourFirstName Part A. HALF A STRING Given a string str1 of even length, print out the first half. Methods to use: substring(), length()

Testing cases:

WooHoo HelloThere abcdef ab 0123456789 kitten

Part B. WITHOUT ENDS

=> Woo => Hello => abc

=> a => 01234 => kit

Given a string str1, print out the string without the first and last char. The string length is at least 2. Methods to use: substring(), length() Testing cases:

Hello java coding code ab Chocolate! kitten woohoo

=> ell => av => odin => od => (empty string) => hocolate

=> itte => ooho

Part C. ROTATE LEFT

Given a string str1, print out a rotated left 2 version where the first 2 chars are moved to the end. The string length will be at least 2.

Methods to use: substring(), length() Testing cases:

Hello => lloHe java => vaja Hi => Hi code => deco cat => tca 12345 => 34512 Chocolate => ocolateCh bricks => icksbr

Part D. COUNT HI

Given a string, output the number of times the string hi appears anywhere in the string. Methods to use: substring(), length(), equals() Testing cases:

abc hi ho =>1 ABChi hi =>2 hihi =>2 hiHIhi =>2 h =>0 hi =>1 Hi is no HI on ahI =>0 hiho not HOHIhi =>2

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Temple Of Django Database Performance

Authors: Andrew Brookins

1st Edition

1734303700, 978-1734303704

More Books

Students also viewed these Databases questions

Question

Why do HCMSs exist? Do they change over time?

Answered: 1 week ago