The string problems that I did today weren't very long, but they required a lot of thinking about really the technical things.
The problem for today:
Given a string, return true if it ends in "ly".
endsLy("oddly") → true
endsLy("y") → false
endsLy("oddy") → false
public boolean endsLy(String str) {
if ( str.length()>=2 && str.substring(str.length()-2, str.length()).equals("ly"))
// if the string length is 2 or larger, then we can always have the possibility of it ending with ly. if the last 2 characters of the string is equals to the string "ly"
{
return true;
// then return true.
}
return false;
// if the above conditions are not met, then return false.
}
I am doing my presentation for the end of the semester on Tuesday. I am looking forward to it because even though I don't have one big project to present, it will be an interesting sort of presentation.
No comments:
Post a Comment