For an assignment this week for my Java class I am supposed to use a provided sample
Question:
For an assignment this week for my Java class I am supposed to use a provided sample code that cannot be edited, and add a method called isPalindrome. The full code is supposed to retrieve string values from the command line prompt and determine if they are palindromes (while ignoring nonalphabetical characters). It also specifies in all caps NOT to use regular expressions.I DO have something written that I feel likeshouldwork but I keep getting the same error: "String cannot be converted to String[]". Which I know objectively, but I am confused about how to set up this kind of comparison method without using a boolean, or how I need to rework my method. I do think the part simply comparing them is right but I don't know how to get it working as intended (at least not without editing the main method). This is what I have right now:
Required starter code supplied (CAN NOT EDIT)
public class Palindrome {
public static void main(String[] args){
if (args.length == 0) {
return;
}
for (int i = 0; i < args.length; i++) {
if (isPalindrome(args[i])){
System.out.println(args[i] + " is a palindrome");
} else {
System.out.println(args[i] + "is not a palindrome");
}
}
} //end of required Starter Code
public boolean isPalindrome(String[] args){
for (int i = 0; i < args.length;i++){
if (!args[i].equals(args[args.length - i - 1])) return false;
}
return true;
}
}
Could you possibly help me or point me in the right direction for how to rewrite it? Or I guess just let me know if I am way off entirely?