Palindrome number check USING JAVA
A program to accept a number from keyboard and check whether it is Palindrome.
import java.util.Scanner;
public class PalindromeExample {
public static void main(String args[]){
int r,sum=0,temp;
System.out.println("Enter a number to check whether it is Palindrome");
Scanner in = new Scanner(System.in);
int n=in.nextInt(); //It is the number variable to be checked for palindrome
int finalPrint = n;
temp=n;
while(n>0){
r=n%10; //getting remainder
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
System.out.println(finalPrint +" is a palindrome number.");
else
System.out.println(finalPrint +" is not a palindrome number.");
}
}
Output:
Enter a number to check whether it is Palindrome
4554
4554 is a palindrome number.
Great blog. This is an interesting problem, thank you for sharing its solution. Learning data structures and algorithms in Python or Java can help people develop solid problem-solving skills as well as cracking the coding interviews. Great blog.
ReplyDelete