I'm getting a return statement error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Heyjude579
    New Member
    • Nov 2011
    • 2

    I'm getting a return statement error

    I'm new to Java. I'm getting the following error from my code:
    (Palindrome.jav a:30: error: missing return statement
    } // close method)


    My code is:

    [public class Palindrome { // define class palindrome

    public static boolean isPalindrome(St ring inputWord) { //define method

    int rightSide = inputWord.lengt h() -1; // right side

    while (leftSide < rightSide) { //loops until middle is found.
    if ((inputWord.cha rAt(leftSide))! = (inputWord.char At(rightSide))) {
    return false; // when letters on each side are not equal
    // a false value is returned.
    } else {
    return true; } // if finished, all chars were same

    } // close while stmt

    } // close method

    } // close class ]
  • Leen
    New Member
    • Aug 2010
    • 22

    #2
    maybe this is not the error
    but r u define the 2 fields : leftSide and rightSide??

    Comment

    • Rabbit
      Recognized Expert MVP
      • Jan 2007
      • 12517

      #3
      It's probably because there exists the possibility that you never return anything.

      Comment

      • kuldeeprsks
        New Member
        • Dec 2011
        • 22

        #4
        1. In While loop the condition is
        tested first and then the statements are executed if the condition turns out to
        be true.
        In do while the statements are executed for the first time and then the conditions
        are tested, if the condition turns out to be true then the statements are
        executed again.

        All block in method isPalindrome is not return a value.
        Place a return between //close while and //close method.

        Comment

        • Leen
          New Member
          • Aug 2010
          • 22

          #5
          the first mistake: u check the first and the last letter in ur string ONLY, for example if u have the word: " lamikal "--> the first letter is ' l ' and the last is 'l', but it is not a palindrome...
          u will increment the leftSide and decrement the rightSide after each check

          Comment

          Working...