Hello, so the project I'm working on requires a method to check for a palindrome. First the code i'm using.
What my idea is is to use a nested for loop to check the character at the end, and at the beginning and if they match, check the next one, and repeat. I know why this isn't working after checking it how I did. It cycles through the for loop with the variable 'b' first then decrements a by 1 then checks all of the 'b' variables again and repeats. This is the only way I could think to do this and I don't know how to fix it. Any recommendations? Thanks!
Note: After I posted this the code copied and pasted incorrectly. It has "/<"'s in it that arent there in my actual code and in the println()'s the 'b's' are lowercase.
public class Panlindrome {
public static void main(String[] args) {
isPalindrome("racecar");
}
public static void isPalindrome(String text) {
text.trim();
for (int a = text.length() - 1; a >= 0; a--) {
for (int b = 0; b <= text.length() - 1; b++) {
if (text.charAt(a) == text.charAt(B)/>) {
System.out.println(a + " " + B)/>;
} else {
System.out.println(a + " " + B)/>;
}
}
}
}
}
What my idea is is to use a nested for loop to check the character at the end, and at the beginning and if they match, check the next one, and repeat. I know why this isn't working after checking it how I did. It cycles through the for loop with the variable 'b' first then decrements a by 1 then checks all of the 'b' variables again and repeats. This is the only way I could think to do this and I don't know how to fix it. Any recommendations? Thanks!
Note: After I posted this the code copied and pasted incorrectly. It has "/<"'s in it that arent there in my actual code and in the println()'s the 'b's' are lowercase.