Ask Question
14 February, 15:04

Write a function checkPalindrome that accepts a single argument, a string. The function should return true (Boolean) if the string is a palindrome, false if it is not. Make sure your function will give the correct answer for words with capital letters.

+1
Answers (1)
  1. 14 February, 16:29
    0
    Following are the program in the Java Programming Language.

    //define function

    public static boolean checkPalindrome (String str) {

    //set integer variable to 0

    int a = 0;

    //set integer variable to store the length of the string

    int n = str. length () - 1;

    //set the while loop to check the variable a is less than the variable n

    while (a
    {

    //check the string character is not in the variable n

    if (str. charAt (a) ! = str. charAt (n))

    //then, return false

    return false;

    //the variable a is incremented by 1

    a++;

    //the variable n is decremented by 1

    n--;

    }

    //and return true

    return true;

    }

    Explanation:

    Following are the description of the following function.

    Firstly, we define boolean type public function that is 'checkPalindrome' and pass string data type argument 'str' in its parameter. Set two integer data type variables that are 'a' initialize to 0 and 'n' which store the length of the string variable 'str' decremented by 1. Set the While loop that checks the variable 'a' is less than the variable 'n', then we set the If conditional statement to check that the string character is not in the variable n then, return false. Otherwise, it returns true.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a function checkPalindrome that accepts a single argument, a string. The function should return true (Boolean) if the string is a ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers