Respuesta :
Answer:
public static void printPalindrome(Scanner console) {
System.out.print("Type one or more words: ");
String word = console.next();
String comp="";
String word2=word.toLowerCase();
for(int i=word2.length()-1;i>=0;i--){
comp+=word2.charAt(i);
}
System.out.println();
if(comp.equals(word2)){
System.out.println( word + " is a palindrome!");
}else{
System.out.println(word + " is not a palindrome.");
}
}
Explanation:
Here is the code!
Answer:
Here's the code in Java with appropriate comments
Explanation:
public static void printPalindrome(Scanner console) {
System.out.println("Word please! ");
String s = console.next();
//checking the boolean expression if true
boolean isPalendrome = true;
for (int i = 0; i < s.length() / 2; i++) {
char p = s.charAt(i);
char q = s.charAt(s.length() - i - 1);
//applying an else conditional
if (p != q) {
isPalendrome = false;
break;
}
}
//printing if we check and evaluate it to be a palindrome
if (isPalendrome)
System.out.println("Palindrome detected!");
}
Source(s):
Sun Certified Java Programmer 5.0