notString

Given a string, return a new string where “not ” has been added to the front. However, if the string already begins with “not”, return the string unchanged. Note: use .equals() to compare 2 strings.

notString(“candy”) -> “not candy”
notString(“x”) ->”not x”
notString(“not bad”)-> “not bad”

public String notString(String str) {
if(str.length()>=3){
if(str.substring(0,3).equals("not"))
return str;
else return "not "+str;
}
else return "not "+str;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s