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
Is a boolean variable?
What is the collection interface?
How is string immutable in java?
What is static data type in java?
What is a type parameter in java?
What is method overloading with type promotion?
Enlist diffrent types of inheritance supported by java?
How do you break a loop?
What is a loop java?
What is a method header?
What does the append?
What are the default and parameterized constructors?
List some java keywords sun like c, c + + keywords?
What is the final access modifier in java?
Write a program to print fibonacci series