To Check Whether A Number is Pallindrome Or Not
import java.io.*;
public class Palindrome {
public static void main(String [] args){
try{
BufferedReader object = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter a number");
int num= Integer.parseInt(object.readLine());
int n = numb;
int rev=0;
System.out.println("The Number is : ");
System.out.println(" "+ numb);
for (int i=0; i<=num; i++){
int r=numb%10;
numb=numb/10;
rev=rev*10+r;
i=0;
}
System.out.println("Output after reversing: "+ " ");
System.out.println(" "+ rev);
if(n == rev){
System.out.print("This Number is Palindrome!");
}
else{
System.out.println("This Number is not palindrome!");
}
}
catch(Exception e){
System.out.println("Unknown Number!");
}
}
}
Loading...
|
Comments :
Post a Comment