...

/

Solution Review: Is String a Palindrome?

Solution Review: Is String a Palindrome?

Have a look at the solution to the 'Is String a Palindrome?' challenge.

Rubric criteria

Solution

Press + to interact
class Palindrome
{
public static void main(String args[])
{
System.out.println( checkPalindrome("madam"));
}
public static boolean checkPalindrome(String str)
{
if (str.length() == 0)
{
return true;
}
else
{
String reversedString = "";
String currLetter;
for(int i=0; i < str.length(); i++)
{
currLetter = str.substring(i,i+1);
// add the letter at index i to what's already reversed.
reversedString = currLetter + reversedString;
}
if(str.equals(reversedString))
{
return true;
}
else
{
return false;
}
}
}
}

Rubric-wise explanation


Point 1:

Look at the header of the checkPalindrome() method at line 8. It’s a ...