Exercise
Function Palindrome, iterative
Objetive
Write an java iterative function to say whether a string is symmetric (a palindrome). For example, "RADAR" is a palindrome.
Example Code
public class Main
{
public static boolean IsPalindrome(String text)
{
text = text.toUpperCase();
int begin = 0;
int end = text.length() - 1;
for (begin = 0; begin < end; begin++)
{
if (text.charAt(begin) != text.charAt(end))
{
return false;
}
end--;
}
return true;
}
public static void main(String[] args)
{
System.out.println(IsPalindrome("radar"));
System.out.println(IsPalindrome("ratas"));
}
}