First time posting here! Yeah I kind of just need some help with this assignment. We had to read an input file, go through a loop for each character in a line of the input file, and store that info in a char array, and then finally write an isPalindrome method and call it to determine if that line is a palindrome and print it to the console.
This is what I have so far, sorry if I didn't format correctly, it was kind of confusing. I'm still kind of a beginner and I'm not sure where I'm going wrong. My output is essentially "[C@91bee48 is not a palindrome!" over and over again with some variation on whether or not its a palindrome.
public class Palindromes {
public static void main(String[] args) {
int k = 0;
try {
Scanner inF = new Scanner(new File("palindromes.txt"));
String aString;
while (inF.hasNextLine()) {
aString = inF.nextLine();
k++;
for (int i = 0; i < k; i++) {
char[] phrases = new char[aString.length()];
if (Character.isLetter(aString.charAt(k))) {
phrases[i] = aString.charAt(i);
}
isPalindrome(phrases);
}
}
}
catch (FileNotFoundException e) {
System.err.println("palindromes.txt not found!");
}
}
public static void isPalindrome(char[] phrases) {
boolean isPalindrome = false;
int i1 = 0;
int i2 = phrases.length - 1;
while (i2 > i1) {
if (phrases[i1] != phrases[i2]) {
isPalindrome = false;
System.out.println(phrases + " is not a palindrome!");
} else {
isPalindrome = true;
System.out.println(phrases + " is a palindrome!");
}
i1++;
i2--;
}
}
}