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
What is the difference between a method and a function in alice?
Which command from the jdk compiles a java program?
What is a flag variable?
What is tcp ip in java?
What is difference between word and integer?
What does localhost mean?
Tell me how many ways are there to initialise an integer with a constant.
Can a static member function access member variable of an object?
Can constructor be protected in java?
What is difference between equal and == in java?
Why wait(),notify(),notifyAll() methods defined in Object class althought we are using in only threads.
Why should I use abstract class?
What is vector capacity in java?
When a thread is executing synchronized methods , then is it possible to execute other synchronized methods simultaneously by other threads?
Which is fastest collection in java?