//wap to check String is palindrome or not?
package govindtest;
import java.util.Scanner;
public class StringPalindromeCheck {
public static void main(String[] args) {
System.out.println("enter String");
Scanner s1=new Scanner(System.in);
String s2=s1.nextLine();
char[] ch = s2.toCharArray();
int j=ch.length-1;
int i=0;
while(i<j)
{
if(ch[i]!=ch[j])
{
System.out.println("Not Palindrome");
return;
}
i++;
j--;
}
System.out.println("String Is palindrome");
}
}
package govindtest;
import java.util.Scanner;
public class StringPalindromeCheck {
public static void main(String[] args) {
System.out.println("enter String");
Scanner s1=new Scanner(System.in);
String s2=s1.nextLine();
char[] ch = s2.toCharArray();
int j=ch.length-1;
int i=0;
while(i<j)
{
if(ch[i]!=ch[j])
{
System.out.println("Not Palindrome");
return;
}
i++;
j--;
}
System.out.println("String Is palindrome");
}
}
====================================================================
package govindtest;
import java.util.Scanner;
public class CheckPalindromeString {
public static void main(String[] args) {
System.out.println("Enter String");
Scanner s1=new Scanner(System.in);
String s2=s1.nextLine();
StringBuffer sb=new StringBuffer(s2).reverse();
if(s2.contentEquals(sb))
{
System.out.println("PalinDrome");
}
else
{
System.out.println("Not Palindrome");
}
}
}
No comments:
Post a Comment