A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Write a program to find palindrom of a string in java

import java.util.Scanner;

class Student
{
    public static void main(String args[])
    {
       
        char s[]=new char[10];
        int i,j,flag=1,len;

        System.out.println("enter ur string and integer");

        Scanner src=new Scanner(System.in);
        String name = src.next();
        s=name.toCharArray();
                int length=s.length;

                for(i = 0,j=length-1; i<length; i++, j--)  
            {
                if(s[i]!=s[j])
                {
                    flag=0;
                    break;
                }
            }

        if(flag!=0)
                {
        //if flag is true.
        System.out.println("it is a palindrome");
                }
        else
        System.out.println("it is not a palindrome");
    }
}



Sample output:


run:
enter ur string and integer
heera
it is not a palindrome



LEARN TUTORIALS

.

.