PROGRAM TO CHECK THE GIVEN STRING IS PALINDROME OR NOT

import java.io.*; class Pallian {             public boolean ispalliandrome(String str)             {                         Sy...

import java.io.*;
class Pallian
{
            public boolean ispalliandrome(String str)
            {
                        System.out.println("given string is"+str);
                        int n=str.length();
                        boolean flag=true;
                        for(int i=0; i<=n/2; i++)
                        {
                                    if(str.charAt(i)!=str.charAt(n-i-1))
                                    flag=false;
                        }
                        return flag;
             }
}
class Palliandrome
{
            public static void main(String args[])
            {
                        Pallian p=new Pallian();
                        String str="MADAM";
                        if(p.ispalliandrome (str))
                        {
System.out.println("GIVEN STRING IS PALINDROME”);
                        }
                        else
                        {
System.out.println("GIVEN STRING IS  NOT PALINDROME ");
                        }
            }
}


OUTPUT:

GIVEN STRING ISMADAM

GIVEN STRING IS PALINDROME

Related

Finalizer Method in Java

FINALIZER METHODS: We have seen that a constructor method is used to initialize an object when it is declared. This process is known as initialization. similarly,java supports a concept called fi...

How to Hide Class in a Package?

Hiding classes: When we import a package using astric(*),all public classes are imported.however ,we may preffer to “not import”certain classes.i.e,we may like to hide these classes from accessing ...

How to add a new Class to a Package?

Adding a class to a package: It is simple to add a class to an existing  package.consider the following package. package p1; public classA { Body of A } The package p1 contains one p...

Post a Comment

emo-but-icon
:noprob:
:smile:
:shy:
:trope:
:sneered:
:happy:
:escort:
:rapt:
:love:
:heart:
:angry:
:hate:
:sad:
:sigh:
:disappointed:
:cry:
:fear:
:surprise:
:unbelieve:
:shit:
:like:
:dislike:
:clap:
:cuff:
:fist:
:ok:
:file:
:link:
:place:
:contact:

item