Java, .NET, PHP, PYTHON, ANGULAR, ML, Data Science, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Palindrome Program in Java 

Pallindorm means from left to right and right to left string should be matched.

Pallindorm can be an integer as well as a string both.

This program is used to check palindrome using String.

class Checkpallindrom
{

     public static void main(String args[])
     {
          char arr[] = {'m','a','d','a','n'};
          int i,j;
          boolean flag=true;
          for(i=0,j=arr.length-1;i<arr.length/2;i++,j--)
          {
                if(arr[i]!=arr[j])
                {
                    flag=false;
                    System.out.println("Not Pallindrom");
                    break;

                }

          }
         if(flag)
         System.out.println("Pallindrom");


     }


}



2 Comments

If you have any doubt in programming or join online classes then you can contact us by comment .

  1. Pallindrom program without using third variable?

    import java.util.Scanner;
    class Pallindrom
    {

    public static void main(String args[])
    {
    // char arr[] = {'d','a','m','a','n'};
    int i,j;
    Scanner sc= new Scanner(System.in);
    System.out.println("Enter size of char array");
    char arr[] = new char[sc.nextInt()] ;
    for(i=0;i 'A'

    }
    for(i=0,j=arr.length-1 ; i<arr.length/2; i++,j--)
    {
    if(arr[i]!=arr[j])
    {
    System.out.println("NOT Pallindrom");
    break;
    }


    }
    if(i==arr.length/2)
    System.out.println("Pallindrom");

    }


    }

    ReplyDelete
  2. Program to check Pallindrom using String?
    import java.util.Scanner;
    class Pallindrom
    {

    public static void main(String args[])
    {

    int i,j;
    Scanner sc= new Scanner(System.in);
    System.out.println("Enter String");
    String arr = sc.next();
    for(i=0,j=arr.length()-1 ; i<arr.length()/2; i++,j--)
    {
    if(arr.charAt(i)!=arr.charAt(j))
    {
    System.out.println("NOT Pallindrom");
    break;
    }


    }
    if(i==arr.length()/2)
    System.out.println("Pallindrom");

    }


    }

    ReplyDelete

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post