Jump to content

Please Help

- - - - -

  • Please log in to reply
3 replies to this topic

#1
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
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(

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
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
roxin_phoenix

roxin_phoenix

    Newbie

  • Members
  • PipPip
  • 19 posts
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
lina

lina

    Learning Programmer

  • Members
  • PipPipPip
  • 34 posts
Thank you guys for help.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users