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 high-level thread states in java programming?
Is there any difference between synchronized methods and synchronized statements?
what is singleton in java?
Is arraylist dynamic in java?
What do you understand by looping in java? Explain the different types of loops.
what is the volatile modifier for? : Java thread
What are generic methods?
Can we override constructors in java?
What is an exception in java?
Can static methods be inherited?
What is unicode with example?
What are the differences between this and super keyword?
Can a class have an interface?
Explain constructors and types of constructors in java.
What is the difference between multitasking and multithreading in Java