I am really having had time on how to code this program
Write a method called endsWith that takes two Strings as arguments, and returns true if and only if the first String ends with the characters in the second String. I.e., endsWith("hibbert", "bert") is true, and endsWith("hibberty", "bert") is false. Do not use the endsWith method that exists in the String class.
I think that the endsWith method must be boolean:
Boolean endsWith(
3 replies to this topic
#1
Posted 10 December 2010 - 10:29 AM
|
|
|
#2
Posted 10 December 2010 - 10:33 AM
I'll give you a nice hint:
String word = "hibbert"; char lastLetter = word.charAt(word.length() -1 )So word.charAt(word.length() -1 ) will give you the last character.
#3
Posted 26 December 2010 - 07:29 AM
Just use a looping to solve this problem
String word = "hibbert";
String word2 = "bert";
for (int i=0; i<word2.length()-1; i++) {
[INDENT]if (word.charAt(word.length()-1) == word2.chatAt(i))[/INDENT]
[INDENT][INDENT]return true;[/INDENT][/INDENT]
}
return false;
#4
Posted 26 December 2010 - 07:55 AM
Thank you guys for help.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









