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
Can each java object keep track of all the threads that want to exclusively access it?
Can you access non static variable in static context?
What are the differences between Java 1.0 and Java 2.0?
What comes to mind when someone mentions a shallow copy in java?
What is subsequence of a string?
How many types of flags are there?
Does substring create a new object?
What is the implementation of destroy method in java. Is it native or java code?
What is the difference between menuitem and checkboxmenu item?
Explain Basics of OOP Language in java
Define an abstract class with reference to java.
can used Protected Class outside Function.?
What is xslt in java?
Is java hashset ordered?
What is the function of log?