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 are the different approaches to implement a function to generate a random number?
What is the mapping mechanism used by java to identify IDL language?
What state is a thread in when it is executing?
What is a package in java? List down various advantages of packages.
What is singleton service?
What is the difference between serial and throughput garbage collector?
Describe what a thread-local variable is in java?
What is difference between c++ and java ?
What is ide with example?
What is meant by stack and queue?
How does multithreading take place on a computer with a single cpu?
What is polymorphism java example?
Which software is used for java programming?
What is functional interface in java example?
take an array with -ve and +ve value both.find out the nearest value of 0(zero).if two values are same like(-2 and +2)then extract +2 is nearest of 0(zero).