Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
9 views2 pages

Palindrome

The document contains a Java program that checks if a given word is a palindrome. It defines a method to compare characters from the start and end of the word, ignoring case. The program prompts the user for input and outputs whether the word is a palindrome or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views2 pages

Palindrome

The document contains a Java program that checks if a given word is a palindrome. It defines a method to compare characters from the start and end of the word, ignoring case. The program prompts the user for input and outputs whether the word is a palindrome or not.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Activity 3

Output:

Program:
import java.util.Scanner;

class main {

public static boolean isPalindrome(String word) {


int start = 0;
int end = word.length() - 1;

word = word.toLowerCase();

while (start < end) {


if (word.charAt(start) != word.charAt(end)) {
return false;
}
start++;
end--;
}

return true;
}

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("Enter a word: ");


String word = scan.nextLine();

if (isPalindrome(word)) {
System.out.println(word + " is a palindrome.");
} else {
System.out.println(word + " is not a palindrome.");
}
}
}

You might also like