Write a program to find Whether given string is palindrome or not.
import java.util.Scanner; public class Stringpolindrome { public static void main(String[] args) { int i,j=0; Scanner sc=new Scanner(System.in); System.out.println("Enter your String:-"); String str=sc.next(); char c[]=new char[20]; c=str.toCharArray(); i=str.length(); --i; while(j<=i) { if(c[i]!=c[j]) { System.out.println("The given string "+ str +" is not polindrome"); System.exit(0); } ++j; --i; } System.out.println("The given string" + str +"is polindrome"); } } Output 1:
Enter your String:- javainchennai
The given string javainchennai is not polindrome
OUTPUT-2 :
Enter your String:- malayalam
The given string malayalam is palindrome
No comments:
Post a Comment