5th sem OOPJ Write a program to find that given number or string is palindrome or not.
import java.io.*;
import java.util.*;
/**
*
* @author Yash
*/
class pra7{
public static void main(String arg[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter String :");
int n = sc.nextInt();
int r,sum=0,temp;
temp=n;
while(n>0){
r=n%10; //getting remainder
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println("palindrome number ");
else
System.out.println("not palindrome");
}
}
import java.util.*;
/**
*
* @author Yash
*/
class pra7{
public static void main(String arg[]){
Scanner sc = new Scanner(System.in);
System.out.println("Enter String :");
int n = sc.nextInt();
int r,sum=0,temp;
temp=n;
while(n>0){
r=n%10; //getting remainder
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println("palindrome number ");
else
System.out.println("not palindrome");
}
}
Comments
Post a Comment