My assignment is to see if a string is a palindrome, so I was just going to use a for loop and add each character at i to the new string, and then the next pass through the loop the next character will be placed at [0] and all the other elements will be pushed back 1 spot, so at the end the new string will be the reverse of the input string, and I'll then compare the two strings and if they are = then it will print out "It's a palindrome!", otherwise it will print out "It isn't a palindrome".
I'm not allowed to use a string reverse method, I need to reverse the string myself. I have searched all over and I cannot find an answer to this.
Here is the code I have so far:
class PrimaryClass{
Scanner str = new Scanner(System.in);
String palindrome(String str){
str.toCharArray();
char[] arr = new char[str.length()];
String reverse = "";
for (int i = str.length(); i >= 0; i--){
}
return str;
}
At whatever the index is, I need to place the character that is at that index into the string 'reverse', and push all the other characters back.