I submitted pictures and pasted my code here. My issue is that I do not how to do to make the code work when the string is more than one word. (the instructions are in the pictures attached). This is using Java. public static void printPalindrome(Scanner console ) { System.out.print("Type one or more words: "); String message= console.next(); boolean palindrome= true; int lengthOfMessage= message.length(); for(int i= 0; i
I submitted pictures and pasted my code here. My issue is that I do not how to do to make the code work when the string is more than one word. (the instructions are in the pictures attached). This is using Java.
public static void printPalindrome(Scanner console ) {
System.out.print("Type one or more words: ");
String message= console.next();
boolean palindrome= true;
int lengthOfMessage= message.length();
for(int i= 0; i<message.length(); i++) {
if (Character.toLowerCase(message.charAt(i)) !=
+ Character.toLowerCase(message.charAt(lengthOfMessage-1-i))) {
palindrome = false;
}
}
if (palindrome == true) {
System.out.println();
System.out.print(message+ " is a palindrome!");
}
else {
System.out.println();
System.out.print(message+ " is not a palindrome");
}
}
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images