Skip to main content

Write a Program in java to accept a number and check whether the number is palindrome or not

Write a Program in java to accept a number and check whether the number is palindrome or not.



import java.util.Scanner; 
public class palindromeNumber { 
public static void main(String[] args) { 
Scanner sc = new Scanner(System.in); 
System.out.println("Enter the number : "); 
int n = sc.nextInt(); 
isPallindrome(n); 
sc.close(); 
public static void isPallindrome(int n) { 
int num = n; 
int reverse = 0; 
while (num > 0) { 
int rem = num % 10; 
reverse = reverse * 10 + rem; 
num /= 10; 
if (reverse == n) 
System.out.println(n + " is Palindrome Number."); 
else
System.out.println(n + " is not Palindrome Number."); 
}


OUTPUT: 

Enter the number :
1331
1331 is Palindrome Number


Comments