Write the code for Palindrome ?
Answer Posted / suresh royal
mport java.io.*;
public class Palindrome {
public static void main(String [] args){
try{
BufferedReader object = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("Enter number");
int num= Integer.parseInt(object.readLine());
int n = num;
int rev=0;
System.out.println("Number: ");
System.out.println(" "+ num);
for (int i=0; i<=num; i++){
int r=num%10;
num=num/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!");
}
}
}
| Is This Answer Correct ? | 1 Yes | 0 No |
Post New Answer View All Answers
Differentiate between the constructors and methods in java?
How hashmap increases its size in java?
What is the intersection and union methods?
what is session in java?
What is formatted output?
Does chrome use java?
Are primitives objects?
What is a java applet? What is an interface?
Can we execute a program without main?
Which arithmetic operations can result in the throwing of an arithmeticexception?
Compare overloading and overriding?
What is a null check?
Are true and false keywords?
What is mysql driver class name?
What is a pattern what is an anti pattern?