Advertisement
taweesoft

Untitled

Sep 14th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //elab-source: Lab5.java
  2. import java.util.Scanner;
  3. public class Lab5{
  4.  
  5. public static boolean isPalindrome(long num){
  6. boolean real = true ;
  7.  
  8. long num1=0,num2=num,count = -1,sum = 0,a = 0;
  9.  
  10. while(num2!=0){
  11. count++;
  12. num2 = num2/10;
  13. }
  14. num2 = num ;
  15. while(num2!=0){
  16. num1 = num2%10;
  17. num2 = num2/10;
  18. a = (long)(num1*((long)Math.pow(10L,count)));
  19. sum += a ;
  20. count--;
  21. }
  22. if(sum==num)
  23. real = true ;
  24. else
  25. real = false ;
  26.  
  27. return real ;
  28. }
  29. public static void main (String [] args){
  30. Scanner scanner = new Scanner (System.in);
  31.  
  32. System.out.print("Please Enter a number : ");
  33. long num = (long)Double.parseDouble(scanner.nextLine());
  34. if(isPalindrome(num)){
  35. System.out.print(num+" is palindrome number.");}
  36. else
  37. System.out.print(num+" is not palindrome number.");
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement