Home
Site Map
Useful Tools
Graphing Calc

Scientific Calculator

Introduction to String Projects

These methods are suitable for someone who is just beginning to work with strings and require understanding of concatenation, as well as the String's indexOf() and equals() methods.
Write the body for the methods described below.
public String concatTwice(String str)
Description: This method returns str concatenated with itself .
Method Call return value/output
concatTwice("foo") "foofoo"
concatTwice("a") "aa"
concatTwice("abcdd") "abcddabcdd"
public String concatWithComma(String str)
Description: This method returns str concatenated with itself and with a comma in between
Method Call return value/output
concatWithComma("foo") "foo,foo"
concatWithComma("a") "a,a"
concatWithComma("abcdd") "abcdd,abcdd"
public String sandwich(String bread, String meat)
Description: This method is easiest to understand by looking at the sample calls below
Method Call return value/output
sandwich("a","b") "aba"
sandwich("xy","ab") "xyabxy"
sandwich("hi","bye") "hibyehi"
public int lengthTimesTwo(String str)
Description: This method returns the length of str times 2.
Method Call return value/output
lengthTimesTwo("foo") 6
lengthTimesTwo("a") 2
lengthTimesTwo("abcdd") 10
public boolean isAThere(String str)
Description: This method returns true if the letter "a" is anywhere inside of str . Note: You should use indexOf(). Remember, indexOf() return -1 if it is searching for something that is not there.
Method Call return value/output
isThere("foo") false
isThere("food" ) false
isThere("xay", "a") true
public boolean isThere(String str,String letter)
Description: This method returns true if letter is anywhere inside of str . Note: You should use indexOf().
Method Call return value/output
isThere("foo","f") true
isThere("foo","z") false
isThere("xy", "y") true
public boolean sameStrings(String string1 ,String string2)
Description: This method returns true if string1 and string2 are the same. Use the '.equals()' method.
Method Call return value/output
isThere("foo","f") false
isThere("foo","foo") true
isThere("abc", "cba") false

Challenge Methods.
public String concat5Times(String str)
Description: This method returns str concatenated with itself 5 times (Do this with a loop)
Method Call return value/output
concat5Times("foo") "foofoofoofoofoo"
concat5Times("a") "aaaaa"
concat5Times("abcdd") "abcddabcddabcddabcdd"