Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Please enter your word : ");
- String word = scanner.next().toLowerCase(); //Get user input.
- int wordLength = word.length();
- int counter = 0;
- //Check letters.
- for (int i = 0; i < wordLength / 2; i++) {
- char firstChar = word.charAt(i);
- char lastChar = word.charAt((wordLength-i)-1);
- if (firstChar == lastChar){
- counter++;
- }
- }
- //Print result.
- if (counter == wordLength/2)
- {
- System.out.println("The word is palindrome!");
- }
- else{
- System.out.println("The word is NOT palindrome!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement