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
How does hashset works in java?
How many bytes is string in java?
What is ide with example?
Can you pass by reference in java?
Can a source file contain more than one class declaration?
Difference between process and thread?
What are the states of thread in java?
What is the difference between static method and instance method in Java?
How do you convert boolean to boolean?
Which number is denoted by leading 0x or 0x in java?
What is java util?
What is == and === in javascript?
What is the statements?
What is bufferedreader in java?
Is java still necessary?