Thursday, 19 November 2020

Write a Program in Java to accept a word and check whether it is Palindrome or not.

 import java.util.*;

class string2

{

public static void main(String args[])

{

Scanner in=new Scanner(System.in);

String s,rev=""; int i,len;

System.out.println("Enter a Word");

s=in.next();

len=s.length()-1;

for(i=len;i>=0;i--)

{

rev=rev+s.charAt(i);

}

if(rev.equalsIgnoreCase(s))

    System.out.println(s+" is a Palimdrome Word");

else

    System.out.println(s+" is not a Palimdrome Word");

}

}

No comments:

Post a Comment

Java Program to count the total number of characters in a string

 //Java Program to count the total number of characters in a string import java.util.*; public class CountChars {     public static void mai...