Uncategorized

Write a Java Program to define a function which accept a number and check it is a palindrome number or not

Write a Java Program to define a function which accept a number and check it is a palindrome number or not.

import java.io.*;
import java.util.*;

class Palindrome
{
	void check( int n )
	{
		int rem=0, rev=0, n1=n;
		while( n>0 )
		{
			rem = n % 10;
			rev = rev * 10 + rem ;
			n = n / 10;
		}
		if( n1 == rev)
		  System.out.println(" Number is palindrome.");
		else
			System.out.println(" Number is not palindrome.");
	}
  public static void main(String args[ ])
  {
  	Scanner sc = new Scanner(System.in);
  	int n;
  	System.out.println("Enter n =");
  	n = sc.nextInt();
  	Palindrome ob = new Palindrome( );
  	ob.check( n );
  }
}

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

To Top