proramming : how to determine palindrome



What is Palindrome??


so here is a program on how to determine a palindrome word, feel free to use it for your java programming :

import java.util.Scanner;

public class palindrome
{

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String reverse = ""   ;
        System.out.print("Enter a word: ");
        String word = in.next();
        for (int i = word.length()-1;i>=0;i--){
            reverse = reverse+ word.charAt(i);
         
        }
     
        if (word.equals(reverse)){
            System.out.println("palindrome");}
        else{
            System.out.println("not palindrome");
        }
    }
}


Happy palindrome week!!



 

No comments :

Post a Comment

please be nice here and I will be nice to you..