Advertisement
fahimkamal63

Palindrome

May 25th, 2019
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. /*
  2.  * Palindrome
  3.  * Date : 25.05.19
  4.  */
  5. import java.util.Scanner;
  6. public class Palindrom {
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.         System.out.print("Enter number to check: ");
  10.         int x = input.nextInt();
  11.         if(palin(x)) System.out.println("The number is a Palindrom number.");
  12.         else System.out.println("The number is not a Palindrom number.");
  13.         input.close();
  14.     }
  15.     static boolean palin(int n) {
  16.         int a = n, result = 0;
  17.         while(a != 0) {
  18.             int k = a % 10;
  19.             result *= 10;
  20.             result += k;
  21.             a /= 10;
  22.         }
  23.         if(result == n) return true;
  24.         return false;
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement