import java.io.*;
public class PalindromeExample {
public static void main(String [] args){
try{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter nober");
int no= Integer.parseInt(br.readLine());
int n = no;
int rev=0;
System.out.println("Number: ");
System.out.println(" "+ no);
for (int i=0; i<=no; i++){
int r=no%10;
no=no/10;
rev=rev*10+r;
i=0;
}
System.out.println("After reversing the number: "+ " ");
System.out.println(" "+ rev);
if(n == rev){
System.out.print("Number is palindrome!");
}
else{
System.out.println("Number is not palindrome!");
}
}
catch(Exception e){
System.out.println("Out of range!");
}
}
}
Responses
0 Respones to "22. Palindromes. A palindrome is a number that reads the same forwards and backwards, like 12321. Write a program that tests input integers for the palindrome property."
Post a Comment