Computer Science, asked by jedi1, 1 year ago

write a program in java to accept a word and check whether it is in palindrome or not

Answers

Answered by KimChinkyo
8
public class palindrome
{
String word1="";
int i,p;
char chr;
p=word.length ();
for (i=p-1; i>=0;i--)
{
chr=word.charAt (i);
word1=word1+chr;
}
if (word.equals (word1 ))
System.out.println("Palindrome");
else
System.out.println("Not Palindrome");
}
}
Answered by CopyThat
5

Program :-  {JAVA}

import java.util.*;

public class PalindromeString

{

public static void main(String args [ ] )

{

Scanner scan = new Scanner(System.in);

int length;

String reverseString = '' '' ;

System.out.println(''Enter a word: '');

String inputString = scan.nextLine();

length = inputString.length();

for (int i =length-1; i >=0; i --)

{

reverseString = reverseString + inputString.charAt(i);

}

if (reverseString.equalsIgnoreCase(inputString))

System.out.println(inputString + '' is palindrome'');

else

System.out.println(inputString + '' is not palindrome'');

scan.close();

}

}

Output :-

Enter a word:

Radar

Radar is Palindrome

Similar questions