WHAT'S NEW?
Showing posts with label palindrome. Show all posts
Showing posts with label palindrome. Show all posts

PalindromeWithString.java


class PalindromeWithString 
{
public static void main(String[] args) 
{
String str="dad";

String rev="";

int l=str.length();

for (int i=l-1;i>=0 ;i-- )
{
rev=rev+str.charAt(i);
}

if (str.equals(rev))
{
System.out.println("String is a Palindrome");
}
else
{
System.out.println("String is not a Palindrome");
}
}
}

class PalindromeOfNumber 
{
public static void main(String[] args) 
{
int original=12345;
int o=original;//Stored for reference
int reverse=0;

while( original != 0 )
      {
          reverse = reverse * 10;
          reverse = reverse + original%10;
         original = original/10;
      }
if (o==reverse)
{
System.out.println("Number is palindrome");
}
else
{
System.out.println("Number is not a palindrome");
}
}
}