PART A: HALF A STRINGGiven a string str of even length, print out the first half. Methods to use: substring(), length()Testing cases:WooHoo => WooHelloThere => Helloabcdef => abcab => a0123456789 => 01234kitten => kit(Note that the sample input test cases are shown before the “=>” and the expected output each test case isafter the “=>”. Your program should print out the expected output only, not the input.)PART B: WITHOUT ENDSGiven a string str, print out the string without the first and last char. Assume the string length is at least 2.Methods to use: substring(), length()Testing cases:Hello => ell java => av coding => odin code => od ab => (empty string)Chocolate! => hocolate kitten => itte woohoo => oohoPART C: COMBO STRINGGiven 2 strings, str1 and str2, print out a string of the form short+long+short, with the shorter string on theoutside and the longer string on the inside. Assume the strings will not be the same length, and that they arenot empty.Methods to use: concat(), length()Testing cases:Hello,hi => hiHellohi hi,Hello => hiHellohi aaa,b => baaab b,aaa => baaab aaa,1234 => aaa1234aaa aaa,bb => bbaaabb a,bb => abba bb,a => abba xyz,ab => abxyzabPART D: OMIT INITIALGiven 2 strings, str1 and str2, print out their concatenation, except omit the first character of each. Assumethe string will be at least length 1.Methods to use: substring(), length()Testing cases: Hello,There => ellohere java,code => avaode shotl,java => hotlava ab,xy => by ab,x => b x,ac => c a,x => (empty string)kit,kat => itat mart,dart => artartPART E: ROTATE LEFTGiven a string str, print out a rotated left 2 version where the first 2 chars are moved to the end. Assume thestring length will be at least 2.Methods to use: substring(), length(), concat()Testing cases: Hello => lloHe java => vaja Hi => Hi code => deco cat => tca 12345 => 34512 Chocolate => ocolateCh bricks => icksbrPART F: MIDDLE TWOGiven a string str, print out a string made of the middle two chars. Assume the string length is at least 2 and iseven.Methods to use: substring(), length()Testing cases: string => ri code => od Practice => ct ab => ab 0123456789 => 45PART G: COUNT HIGiven a string str, 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

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter7: Characters, Strings, And The Stringbuilder
Section: Chapter Questions
Problem 12RQ
icon
Related questions
Question

PART A: HALF A STRING
Given a string str of even length, print out the first half.
Methods to use: substring(), length()
Testing cases:
WooHoo => Woo
HelloThere => Hello
abcdef => abc
ab => a
0123456789 => 01234
kitten => kit
(Note that the sample input test cases are shown before the “=>” and the expected output each test case is
after the “=>”. Your program should print out the expected output only, not the input.)
PART B: WITHOUT ENDS
Given a string str, print out the string without the first and last char. Assume the string length is at least 2.
Methods to use: substring(), length()
Testing cases:
Hello => ell
java => av
coding => odin
code => od
ab => (empty string)
Chocolate! => hocolate
kitten => itte
woohoo => ooho
PART C: COMBO STRING
Given 2 strings, str1 and str2, print out a string of the form short+long+short, with the shorter string on the
outside and the longer string on the inside. Assume the strings will not be the same length, and that they are
not empty.
Methods to use: concat(), length()
Testing cases:
Hello,hi => hiHellohi
hi,Hello => hiHellohi
aaa,b => baaab
b,aaa => baaab
aaa,1234 => aaa1234aaa
aaa,bb => bbaaabb
a,bb => abba
bb,a => abba
xyz,ab => abxyzab
PART D: OMIT INITIAL
Given 2 strings, str1 and str2, print out their concatenation, except omit the first character of each. Assume
the string will be at least length 1.
Methods to use: substring(), length()
Testing cases:
Hello,There => ellohere
java,code => avaode
shotl,java => hotlava
ab,xy => by
ab,x => b
x,ac => c
a,x => (empty string)
kit,kat => itat
mart,dart => artart
PART E: ROTATE LEFT
Given a string str, print out a rotated left 2 version where the first 2 chars are moved to the end. Assume the
string length will be at least 2.
Methods to use: substring(), length(), concat()
Testing cases:
Hello => lloHe
java => vaja
Hi => Hi
code => deco
cat => tca
12345 => 34512
Chocolate => ocolateCh
bricks => icksbr
PART F: MIDDLE TWO
Given a string str, print out a string made of the middle two chars. Assume the string length is at least 2 and is
even.
Methods to use: substring(), length()
Testing cases:
string => ri
code => od
Practice => ct
ab => ab
0123456789 => 45
PART G: COUNT HI
Given a string str, 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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Program on Numbers
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT