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
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?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Based on the provided code and the error message youre encountering it seems that the issue lies in ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started